rveltz
November 12, 2024, 5:31pm
1
Hi,
I come across the following performance gap and I am not sure I understand why.
function my_min(a)
val = a[begin]
ind = 0
@inbounds for i in eachindex(a)
if a[i]>val
val = a[i]
ind = i
end
end
ind
end
a = rand(1000)
julia> @btime argmin(a)
4.554 μs (0 allocations: 0 bytes)
325
julia> @btime my_min(a)
1.113 μs (0 allocations: 0 bytes)
325
adienes
November 12, 2024, 5:36pm
2
On recent nightly it seems to be improved compared to 1.11.1
EDIT: Apparently just benchmark noise, seems to be roughly the same.
julia> @benchmark argmin($a)
BenchmarkTools.Trial: 10000 samples with 10 evaluations.
Range (min … max): 1.336 μs … 9.966 μs ┊ GC (min … max): 0.00% … 0.00%
Time (median): 1.956 μs ┊ GC (median): 0.00%
Time (mean ± σ): 2.066 μs ± 614.355 ns ┊ GC (mean ± σ): 0.00% ± 0.00%
█ ▄▁ ▁ ▁ ▂ ▁ ▂ ▃ ▄
█▇███▇███████▄▇██▄█▃█▇▆█▄▆▆▂█▂█▂▂█▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▁▂▁▁▁▇ ▄
1.34 μs Histogram: frequency by time 3.94 μs <
Memory estimate: 0 bytes, allocs estimate: 0.
julia> @benchmark my_min($a)
BenchmarkTools.Trial: 10000 samples with 84 evaluations.
Range (min … max): 818.464 ns … 6.910 μs ┊ GC (min … max): 0.00% … 0.00%
Time (median): 824.762 ns ┊ GC (median): 0.00%
Time (mean ± σ): 876.617 ns ± 154.231 ns ┊ GC (mean ± σ): 0.00% ± 0.00%
█▄▂▁▁▁ ▁
██████▇█▇█▆█▆█▅▆█▅█▄▆▇▅▇▄▄█▅▄▇▅▆█▆▃▇█▄▄█▅▅▇█▄▃▇█▄▃▃█▇▃▃▆█▅▅▃▄ █
818 ns Histogram: log(frequency) by time 1.46 μs <
Memory estimate: 0 bytes, allocs estimate: 0.
julia> versioninfo()
Julia Version 1.12.0-DEV.1613
Commit 366a38e6ed6 (2024-11-12 01:41 UTC)
Build Info:
Official https://julialang.org release
Platform Info:
OS: Linux (x86_64-linux-gnu)
CPU: 14 × Intel(R) Core(TM) Ultra 7 155U
WORD_SIZE: 64
LLVM: libLLVM-18.1.7 (ORCJIT, alderlake)
Threads: 14 default, 0 interactive, 14 GC (on 14 virtual cores)
Environment:
JULIA_MAX_NUM_PRECOMPILE_FILES = 100
JULIA_NUM_THREADS = 14
JULIA_PKG_PRESERVE_TIERED_INSTALLED = true
Vs
julia> @benchmark argmin($a) evals=100000
BenchmarkTools.Trial: 32 samples with 100000 evaluations.
Range (min … max): 1.118 μs … 3.082 μs ┊ GC (min … max): 0.00% … 0.00%
Time (median): 1.164 μs ┊ GC (median): 0.00%
Time (mean ± σ): 1.559 μs ± 691.308 ns ┊ GC (mean ± σ): 0.00% ± 0.00%
█
██▄▃▄▃▁▁▁▁▁▁▁▁▁▃▁▁▁▁▁▁▁▃▁▁▁▁▁▃▁▁▁▁▁▁▃▁▁▁▁▁▁▁▁▁▁▁▃▁▁▁▁▁▁▁▃▁▆ ▁
1.12 μs Histogram: frequency by time 3.08 μs <
Memory estimate: 0 bytes, allocs estimate: 0.
julia> @benchmark my_min($a) evals=100000
BenchmarkTools.Trial: 42 samples with 100000 evaluations.
Range (min … max): 823.790 ns … 2.346 μs ┊ GC (min … max): 0.00% … 0.00%
Time (median): 828.805 ns ┊ GC (median): 0.00%
Time (mean ± σ): 1.194 μs ± 602.326 ns ┊ GC (mean ± σ): 0.00% ± 0.00%
█ ▁
█▁▁▁▁▁▁▇▁▁▁▁▁▁▁▁▅▁▁▁▁▁▅▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▅▅▅▁▁▁▁▁▁▇▁▅█ ▁
824 ns Histogram: log(frequency) by time 2.35 μs <
Memory estimate: 0 bytes, allocs estimate: 0.
julia> versioninfo()
Julia Version 1.11.1
Commit 8f5b7ca12ad (2024-10-16 10:53 UTC)
Build Info:
Official https://julialang.org/ release
Platform Info:
OS: Linux (x86_64-linux-gnu)
CPU: 14 × Intel(R) Core(TM) Ultra 7 155U
WORD_SIZE: 64
LLVM: libLLVM-16.0.6 (ORCJIT, alderlake)
Threads: 14 default, 0 interactive, 7 GC (on 14 virtual cores)
Environment:
JULIA_MAX_NUM_PRECOMPILE_FILES = 100
JULIA_NUM_THREADS = 14
JULIA_PKG_PRESERVE_TIERED_INSTALLED = true