Skip to content

Instantly share code, notes, and snippets.

@samuelcolvin
Created May 25, 2014 09:17
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 samuelcolvin/221794d6829be66b11f3 to your computer and use it in GitHub Desktop.
Save samuelcolvin/221794d6829be66b11f3 to your computer and use it in GitHub Desktop.
JSON print performance with indent
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
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