Welcome to this forum!
We can better engage with your question if you follow the PSA on questions.
The thing that your example is missing is “self contained runnable + mimics your true usecase”. To give an example in style how this could look like:
using BenchmarkTools
I=10;J=11;K=12; N=500; A = rand(N); C=rand(1:N, I, J, K); B=rand(I,J,K);
function update_indices!(A, B, C)
for i in 1:I, j in 1:J, k in 1:K
vector_indices_to_update = C[i,j,k];
A[vector_indices_to_update] += B[i,j,k]
end
end
@btime update_indices!($A, $B, $C)
What you need to do in order to get useful help is write code snippets that initialize A,B,C. “the length of A is significantly larger…” is all fine and dandy, but it is better to simply incorporate that into the sample problem you show us.
Please also think about all the details, and make sure that they all mirror your true usecase. If your real data is not sorted, then you SHOULD NOT give sorted samples; if your real data is Float32 then you give us Float32, etc etc.
Don’t be go :surprised_pikachu: if you post collect(1:10_000)
as a test vector and proposed solutions delete the collect
, a la
julia> @btime sum($(1:1000_000))
2.016 ns (0 allocations: 0 bytes)