Skip to content

Instantly share code, notes, and snippets.

@odow
Created July 21, 2017 01:54
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 odow/600479bf4da04d81bb2f87875e63408b to your computer and use it in GitHub Desktop.
Save odow/600479bf4da04d81bb2f87875e63408b to your computer and use it in GitHub Desktop.
using BenchmarkTools
struct VarRef
x::UInt64
end
function f(A, B)
s = 0
for y in Y
s += X[y]
end
s
end
m = 100_000_000
n = 100_000
X = rand(Int, n);
Y = mod.(rand(Int, m), n) .+ 1;
Z = VarRef.(Y);
U = Dict{VarRef, Int}();
for i in 1:length(X)
U[VarRef(i)] = X[i]
end
println("Array Access")
display(@benchmark f($X, $Y))
println("\nDict Access")
display(@benchmark f($U, $Z))
C:\Users\odow003\.julia\v0.6\CPLEX\src\MOI>D:/Julia/Julia-0.6/bin/Julia.exe benchmark.jl
Array Access
BenchmarkTools.Trial:
memory estimate: 8.93 GiB
allocs estimate: 499488209
--------------
minimum time: 14.547 s (2.61% GC)
median time: 14.547 s (2.61% GC)
mean time: 14.547 s (2.61% GC)
maximum time: 14.547 s (2.61% GC)
--------------
samples: 1
evals/sample: 1
Dict Access
BenchmarkTools.Trial:
memory estimate: 8.93 GiB
allocs estimate: 499488209
--------------
minimum time: 14.247 s (2.78% GC)
median time: 14.247 s (2.78% GC)
mean time: 14.247 s (2.78% GC)
maximum time: 14.247 s (2.78% GC)
--------------
samples: 1
evals/sample: 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment