What is faster:
(A) 'Unpickling' (Loading) a pickled dictionary object, using pickle.load()
or
(B) Loading a JSON file to a dictionary using simplejson.load()
Assuming: The pickled object file exists already in case A, and that the JSON file exists already in case B.
The speed actually depends on the data, it's content and size.
But, anyway, let's take an example json data and see what is faster (Ubuntu 12.04, python 2.7.3) :
Giving this json structure dumped into
test.jsonandtest.picklefiles:Testing script:
Output:
As you can see, unpickling via
pickleis not that fast at all -cPickleis definetely the way to go if you choose pickling/unpickling option.ujsonlooks promising among these json parsers on this particular data.Also,
jsonandsimplejsonlibraries load much faster on pypy (see Python JSON Performance).See also:
It's important to note that the results may differ on your particular system, on other type and size of data.