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.json
andtest.pickle
files:Testing script:
Output:
As you can see, unpickling via
pickle
is not that fast at all -cPickle
is definetely the way to go if you choose pickling/unpickling option.ujson
looks promising among these json parsers on this particular data.Also,
json
andsimplejson
libraries 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.