Last active
December 18, 2015 23:49
-
-
Save simonster/5864205 to your computer and use it in GitHub Desktop.
JLD mmap benchmark
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
using HDF5, JLD | |
const MATRIX_SIZE = 1000 | |
# Write test file | |
x = rand(MATRIX_SIZE, MATRIX_SIZE) | |
jld = jldopen("test.jld", "w") | |
write(jld, "x", x) | |
close(jld) | |
macro s() | |
esc(quote | |
s = 0.0 | |
for i = 1:MATRIX_SIZE, j = 1:MATRIX_SIZE | |
s += (x[i:i, j:j]::Array{Float64, 2})[1] | |
end | |
end) | |
end | |
function no_io() | |
@s | |
s | |
end | |
function standard() | |
jld = jldopen("test.jld") | |
x = read(jld, "x") | |
@s | |
close(jld) | |
s | |
end | |
function mmapped() | |
jld = jldopen("test.jld", mmaparrays=true) | |
x = read(jld, "x") | |
@s | |
close(jld) | |
s | |
end | |
function hyperslab() | |
jld = jldopen("test.jld") | |
x = plain(jld)["x"] | |
@s | |
close(x) | |
close(jld) | |
s | |
end | |
# Burn-in | |
no_io() | |
standard() | |
mmapped() | |
hyperslab() | |
# Performance | |
gc() | |
gc_disable() | |
@time no_io() | |
@time standard() | |
@time mmapped() | |
@time hyperslab() | |
gc_enable() | |
# On my system: | |
# elapsed time: 0.515120963 seconds (no_io) | |
# elapsed time: 0.595511348 seconds (standard) | |
# elapsed time: 0.588954757 seconds (mmapped) | |
# elapsed time: 23.050431843 seconds (hyperslab) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment