Skip to content

Instantly share code, notes, and snippets.

@binarybana
Created October 22, 2012 00:54
Show Gist options
  • Select an option

  • Save binarybana/3929131 to your computer and use it in GitHub Desktop.

Select an option

Save binarybana/3929131 to your computer and use it in GitHub Desktop.
Julia/Python Dictionary Microbenchmark
function stress0(N::Int)
x = Dict{Int,Float64}()
for i = 1:N
x[i] = 0.0
end
return x
end
function stress0prime(N::Int)
x = Dict{Int,Float64}(N)
for i = 1:N
x[i] = 0.0
end
return x
end
function stress2(x::Dict{Int,Float64}, N::Int)
sum = 0::Int
for i = 1:N
sum += get(x,i,0)
end
return sum
end
import random
def stress0(N):
x = {}
for i in xrange(N):
x[i] = 0.0
return x
def stress2(x, N):
sum = 0
for i in xrange(N):
sum += x.get(i,0)
return sum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment