Last active
February 9, 2016 08:23
-
-
Save gajomi/0c184160042ddfc329ab to your computer and use it in GitHub Desktop.
Benchmarks for unique and union methods
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
macro stats(setupexpr,testexpr) | |
quote | |
N = 2^8 | |
results = zeros(N,3) | |
for i = 1:N | |
$setupexpr | |
data = @timed $testexpr | |
results[i,1] = data[2] | |
results[i,2] = Float64(data[3]) | |
results[i,3] = data[4] | |
end | |
μ,σ = mean(results,1),std(results,1) | |
println("time: $(μ[1]) ± $(σ[1])") | |
println("allocation: $(μ[2]) ± $(σ[2])") | |
println("gc time: $(μ[3]) ± $(σ[3])") | |
end | |
end |
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
### ranges ### | |
julia> @stats x=1:2^15 unique(x) | |
time: 3.7159375e-7 ± 4.013905975041092e-8 | |
allocation: 0.0 ± 0.0 | |
gc time: 0.0 ± 0.0 | |
### associative collections ### | |
julia> @stats s=Set(rand(Int64,2^15)) unique(s) | |
time: 0.0009458752031249999 ± 0.0003434409454841642 | |
allocation: 262240.0 ± 0.0 | |
gc time: 0.0 ± 0.0 | |
julia> @stats is=IntSet(collect(1:2^15)) unique(is) | |
time: 0.0009920913906249999 ± 0.00044799769109717927 | |
allocation: 262240.0 ± 0.0 | |
gc time: 0.0 ± 0.0 | |
julia> @stats d=Dict(zip(collect(1:2^15),rand(Int64,2^15))) unique(d) | |
time: 0.0009264861328125 ± 0.0004584347754295683 | |
allocation: 524384.0 ± 0.0 | |
gc time: 2.8284089843750002e-5 ± 0.0002637569369516736 | |
### arrays with small eltypes ### | |
julia> @stats x=rand(Bool,2^18) unique(x) | |
time: 0.00019525041796875 ± 0.0003693199716505484 | |
allocation: 262256.0 ± 0.0 | |
gc time: 5.798378515625e-5 ± 0.00037538094090833673 | |
julia> @stats x=rand(UInt8,2^18) unique(x) | |
time: 0.00016099780078125 ± 8.348396199362076e-5 | |
allocation: 262256.0 ± 0.0 | |
gc time: 0.0 ± 0.0 | |
julia> @stats x=rand(Int8,2^18) unique(x) | |
time: 0.00014154846484374997 ± 6.900272968256993e-5 | |
allocation: 262256.0 ± 0.0 | |
gc time: 0.0 ± 0.0 | |
### Arrays with structural zeros ### | |
julia> @stats A=Bidiagonal(collect(1:2^8),collect(2:2^8),true) unique(A) | |
time: 8.592412499999999e-5 ± 0.0004333578596779919 | |
allocation: 38976.0 ± 0.0 | |
gc time: 2.6895125e-5 ± 0.00043032199999999996 | |
julia> @stats A=Diagonal(collect(1:2^8)) unique(A) | |
time: 0.00013670909765625 ± 0.0013926349651035386 | |
allocation: 27896.33203125 ± 6789.3125 | |
gc time: 6.05116953125e-5 ± 0.0009681871250000008 | |
julia> @stats A=SymTridiagonal(collect(1:2^8),collect(2:2^8)) unique(A) | |
time: 0.0025976334140625 ± 0.0005780271678318505 | |
allocation: 22048.0 ± 0.0 | |
gc time: 0.0 ± 0.0 | |
julia> @stats A=Tridiagonal(collect(2:2^8),collect(1:2^8),collect(2:2^8)) unique(A) | |
time: 5.9102359375e-5 ± 2.468377157018689e-5 | |
allocation: 39040.0 ± 0.0 | |
gc time: 0.0 ± 0.0 | |
julia> @stats A=sparse(Diagonal(collect(1:2^8))) unique(A) | |
time: 6.676669140624998e-5 ± 6.50257387774067e-5 | |
allocation: 23360.0 ± 0.0 | |
gc time: 0.0 ± 0.0 | |
julia> @stats A=sparse(collect(Diagonal(collect(1:2^8)))) unique(A) | |
time: 0.000114723140625 ± 4.7476982803060564e-5 | |
allocation: 34960.0 ± 0.0 | |
gc time: 0.0 ± 0.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment