You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to use sizehint! + push! to fill an array, but it is much slower than the equivalent operation using resize! and indexing. Benchmarks below.
I'm not surprised there's some overhead, and I'd be willing to accept some just to avoid potential bugs resulting from uninitialized data, but the overhead is 10x:
julia>VERSIONv"1.3.0-DEV.377"
julia>f!(arr, N) = ( sizehint!(arr, N); for i in1:N; push!(arr, i); end; arr )
f! (generic function with 1 method)
julia>g!(arr, N) = ( resize!(arr, N); for i in1:N; arr[i] = i; end; arr )
g! (generic function with 1 method)
julia>f!(Int[], 1_000_000) ==g!(Int[], 1_000_000)
true
julia>@benchmarkf!(arr, 1_000_000) setup=(arr=Int[])
BenchmarkTools.Trial:
memory estimate:7.63 MiB
allocs estimate:1--------------
minimum time:3.717 ms (0.00% GC)
median time:3.811 ms (0.00% GC)
mean time:3.870 ms (0.00% GC)
maximum time:6.022 ms (0.00% GC)
--------------
samples:1271
evals/sample:1
julia>@benchmarkg!(arr, 1_000_000) setup=(arr=Int[])
BenchmarkTools.Trial:
memory estimate:7.63 MiB
allocs estimate:1--------------
minimum time:392.328 μs (0.00% GC)
median time:419.459 μs (0.00% GC)
mean time:433.387 μs (0.00% GC)
maximum time:2.653 ms (0.00% GC)
--------------
samples:10000
evals/sample:1
Almost all time is spent in the function _growend!, which in turn is backed by a C function so I can't easily pin-point on what line the slowness is. I have reproduced this in v1.0.3 as well as latest master.
The text was updated successfully, but these errors were encountered:
Replying to my own issue -- I'm not sure I should expect better performance than this. Even in the case of f!, only 3ns are spent for every push! call. The difference in performance may just be explainable by loop optimizations available in g!. There's a few v- operations in the code_native output (vpbroadcastq, vmovdqu) so that's reasonable.
I'll close this issue in a few days unless I find something useful.
I'm trying to use
sizehint!
+push!
to fill an array, but it is much slower than the equivalent operation usingresize!
and indexing. Benchmarks below.I'm not surprised there's some overhead, and I'd be willing to accept some just to avoid potential bugs resulting from uninitialized data, but the overhead is 10x:
Almost all time is spent in the function
_growend!
, which in turn is backed by a C function so I can't easily pin-point on what line the slowness is. I have reproduced this in v1.0.3 as well as latest master.The text was updated successfully, but these errors were encountered: