Created
May 25, 2014 09:17
-
-
Save samuelcolvin/221794d6829be66b11f3 to your computer and use it in GitHub Desktop.
JSON print performance with indent
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
Previous performance: | |
elapsed time: 7.237158689 seconds (2688899208 bytes allocated) | |
Performance with indent implemented: | |
elapsed time: 10.58000847 seconds (2789486440 bytes allocated) - indent set to 0 | |
elapsed time: 11.382926355 seconds (3966498496 bytes allocated) - indent set to 2 |
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 JSON | |
function generate_jagged(l1, l2) | |
data = Any[] | |
arrays_only = true | |
randrand(maxlen) = rand(int(rand()*maxlen)) | |
for r in rand(int(l1)) | |
if r < 0.25 | |
if arrays_only | |
push!(data, string(randrand(l2))) | |
else | |
push!(data, {string(i)=>int(i*10) for i = randrand(l2)}) | |
end | |
elseif r < 0.5 | |
push!(data, randrand(l2)) | |
elseif r < 0.75 | |
push!(data, int(10*randrand(l2))) | |
else | |
if arrays_only | |
push!(data, [nothing for i = randrand(l2)]) | |
else | |
push!(data, {string(int(i))=>nothing for i = 10*randrand(l2)}) | |
end | |
end | |
end | |
data | |
end | |
data = generate_jagged(1e5, 500) | |
sio = IOBuffer() | |
JSON.print(sio, data) | |
@time JSON.print(sio, data) | |
close(sio) | |
sio = IOBuffer() | |
JSON.print(sio, data, 2) | |
@time JSON.print(sio, data, 2) | |
close(sio) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment