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
2 Likes
adienes
November 12, 2024, 5:36pm
2
2 Likes
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
1 Like