I compared the time complexity with this code:
import json
import random
import time
Ns = 10, 100, 1000, 10000, 100000, 200000, 300000, 600000, 1000000
for N in Ns:
l = [random.random() for i in xrange(N)]
t0 = time.time()
s = json.dumps(l)
t1 = time.time()
dt = t1-t0
print "%s %s" % (N, dt)
On my machine, the result is:
10 7.20024108887e-05
100 0.000385999679565
1000 0.00362801551819
10000 0.036504983902
100000 0.366562128067
200000 0.73614192009
300000 1.09785795212
600000 2.20272803307
1000000 3.6590487957
First column: list length; second column: time for serialization. Building (e.g. xmgrace) shows an ideal linear relationship.
source
share