Skip to content

Instantly share code, notes, and snippets.

@lukego
Last active November 1, 2023 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukego/cedc2607c08ef4f7613c3d215d7293cc to your computer and use it in GitHub Desktop.
Save lukego/cedc2607c08ef4f7613c3d215d7293cc to your computer and use it in GitHub Desktop.
Julia benchmark from slack
using Random: rand!
using LoopVectorization: @turbo
function test_fct(vec_, r1, r2)
xx = vec_
rand!(r1)
rand!(r2)
for j in 1:11
@turbo for i in eachindex(xx, r1, r2)
xx[i] = xx[i] < r1[i] ? r2[i] : xx[i]
end
end
return xx
end
function sim_test(vec_, L::Int)
xx = vec_
r1 = Vector{Float32}(undef, L)
r2 = similar(r1)
for i in 1:250
xx = test_fct(vec_, r1, r2)
end
return xx
end
function main(L=500_000)
test_vect = Vector{Float32}(undef, L)
rand!(test_vect)
sim_test(test_vect, L)
end
#=
julia> @benchmark main()
BenchmarkTools.Trial: 23 samples with 1 evaluation.
Range (min … max): 210.521 ms … 228.047 ms ┊ GC (min … max): 0.00% … 0.00%
Time (median): 219.803 ms ┊ GC (median): 0.00%
Time (mean ± σ): 220.048 ms ± 3.735 ms ┊ GC (mean ± σ): 0.03% ± 0.13%
▁ ▁ ▁ █ ▁ ▁▁▁██▁ ▁ ▁█▁▁ ▁ ▁ ▁
█▁▁▁▁▁▁▁▁▁▁▁▁█▁▁▁▁▁▁▁█▁█▁▁█▁██████▁█▁▁▁████▁▁▁▁▁▁▁▁█▁█▁▁▁▁▁▁█ ▁
211 ms Histogram: frequency by time 228 ms <
Memory estimate: 5.72 MiB, allocs estimate: 6.
shell> head /proc/cpuinfo
processor : 0
vendor_id : AuthenticAMD
cpu family : 23
model : 113
model name : AMD Ryzen 7 3700X 8-Core Processor
stepping : 0
microcode : 0x8701013
cpu MHz : 3594.207
cache size : 512 KB
physical id : 0
=#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment