Last active
March 21, 2020 04:14
-
-
Save ceptreee/38e5307c2f686be43b5e4708ab0b3aac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using BechmarkTools | |
# https://ja.coder.work/so/julia/715798 | |
function test1!(foo1,foo2,foo3) | |
foo3 = foo1 + foo2; | |
return foo3 | |
end | |
function test2!(foo1,foo2,foo3) | |
@. foo3 = foo1 + foo2; | |
return foo3 | |
end | |
function test3!(foo1,foo2,foo3) | |
for i in eachindex(foo2) | |
foo3[i] = foo1[i] + foo2[i] | |
end | |
return foo3 | |
end | |
N = 10000; | |
foo1 = rand(N,N); | |
foo2 = rand(N,N); | |
foo3 = similar(foo1); | |
@benchmark test1!(foo1,foo2,foo3) | |
@benchmark test2!(foo1,foo2,foo3) | |
@benchmark test3!(foo1,foo2,foo3) | |
""" | |
julia> @benchmark test1!(foo1,foo2,foo3) | |
BenchmarkTools.Trial: | |
memory estimate: 762.94 MiB | |
allocs estimate: 2 | |
-------------- | |
minimum time: 344.411 ms (0.09% GC) | |
median time: 376.076 ms (8.35% GC) | |
mean time: 377.700 ms (8.30% GC) | |
maximum time: 414.821 ms (17.22% GC) | |
-------------- | |
samples: 14 | |
evals/sample: 1 | |
julia> @benchmark test2!(foo1,foo2,foo3) | |
BenchmarkTools.Trial: | |
memory estimate: 0 bytes | |
allocs estimate: 0 | |
-------------- | |
minimum time: 139.872 ms (0.00% GC) | |
median time: 142.623 ms (0.00% GC) | |
mean time: 143.080 ms (0.00% GC) | |
maximum time: 147.802 ms (0.00% GC) | |
-------------- | |
samples: 35 | |
evals/sample: 1 | |
julia> @benchmark test3!(foo1,foo2,foo3) | |
BenchmarkTools.Trial: | |
memory estimate: 0 bytes | |
allocs estimate: 0 | |
-------------- | |
minimum time: 131.975 ms (0.00% GC) | |
median time: 133.445 ms (0.00% GC) | |
mean time: 134.389 ms (0.00% GC) | |
maximum time: 145.454 ms (0.00% GC) | |
-------------- | |
samples: 38 | |
evals/sample: 1 | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment