Created
October 22, 2012 00:54
-
-
Save binarybana/3929131 to your computer and use it in GitHub Desktop.
Julia/Python Dictionary Microbenchmark
This file contains hidden or 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
| 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 |
This file contains hidden or 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
| 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