Skip to content

Instantly share code, notes, and snippets.

@tomasaschan
Last active August 29, 2015 14:02
Show Gist options
  • Select an option

  • Save tomasaschan/05c5425a6cf278b7839c to your computer and use it in GitHub Desktop.

Select an option

Save tomasaschan/05c5425a6cf278b7839c to your computer and use it in GitHub Desktop.
Benchmarking some norms
function bench(N)
Base.vecnorm(rand(N,N),Inf)
maximum(abs(rand(N,N)))
Base.maxabs(rand(N,N))
if N < 100
@time for i in 1:100; Base.vecnorm(rand(N,N),Inf); end
@time for i in 1:100; maximum(abs(rand(N,N))); end
@time for i in 1:100; Base.maxabs(rand(N,N)); end
elseif N < 1000
@time for i in 1:10; Base.vecnorm(rand(N,N),Inf); end
@time for i in 1:10; maximum(abs(rand(N,N))); end
@time for i in 1:10; Base.maxabs(rand(N,N)); end
else
@time Base.vecnorm(rand(N,N),Inf)
@time maximum(abs(rand(N,N)))
@time Base.maxabs(rand(N,N))
end
nothing
end
julia> bench(10)
elapsed time: 0.000119376 seconds (92800 bytes allocated)
elapsed time: 0.000138345 seconds (182400 bytes allocated)
elapsed time: 0.000111874 seconds (92800 bytes allocated)
julia> bench(99)
elapsed time: 0.025234709 seconds (7849600 bytes allocated)
elapsed time: 0.012339054 seconds (15696000 bytes allocated)
elapsed time: 0.010975818 seconds (7849600 bytes allocated)
julia> bench(100)
elapsed time: 0.00421132 seconds (800800 bytes allocated)
elapsed time: 0.005647089 seconds (1601280 bytes allocated)
elapsed time: 0.002383772 seconds (800800 bytes allocated)
julia> bench(999)
elapsed time: 0.160477964 seconds (79841280 bytes allocated, 24.95% gc time)
elapsed time: 0.172013959 seconds (159681920 bytes allocated, 33.58% gc time)
elapsed time: 0.120124631 seconds (79841280 bytes allocated, 25.25% gc time)
julia> bench(1000)
elapsed time: 0.009469991 seconds (8000112 bytes allocated)
elapsed time: 0.012288029 seconds (16000160 bytes allocated)
elapsed time: 0.008734959 seconds (8000112 bytes allocated)
0.9999979735960647
julia> bench(9999)
elapsed time: 1.02456819 seconds (799840128 bytes allocated, 3.16% gc time)
elapsed time: 1.148100464 seconds (1599680192 bytes allocated, 2.63% gc time)
elapsed time: 0.919410751 seconds (799840128 bytes allocated)
0.999999980411099
julia> bench(10000)
elapsed time: 1.028318045 seconds (800000112 bytes allocated, 3.19% gc time)
elapsed time: 1.157297922 seconds (1600000160 bytes allocated, 2.62% gc time)
elapsed time: 0.924634062 seconds (800000112 bytes allocated)
0.999999962403813
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment