Skip to content

Instantly share code, notes, and snippets.

@ssato
Created December 14, 2015 17:25
Show Gist options
  • Save ssato/eb72d5c1e6214ffea0e4 to your computer and use it in GitHub Desktop.
Save ssato/eb72d5c1e6214ffea0e4 to your computer and use it in GitHub Desktop.
json_vs_bson_vs_msgpack_vs_...
In [1]: import anyconfig
...
In [3]: save = lambda obj, fname, **kwargs: anyconfig.dump(obj, os.path.join("/tmp", fname), **kwargs)
In [4]: ipdata = anyconfig.load("/tmp/fleure-tests-ouZIjr/packages.json")
...
In [6]: %lprun -T /tmp/ips.json.lprof -f save save(ipdata, "ips.json")
Timer unit: 1e-06 s
Total time: 0.151962 s
File: <ipython-input-3-cc541fcd0a9b>
Function: <lambda> at line 1
Line # Hits Time Per Hit % Time Line Contents
==============================================================
1 1 151962 151962.0 100.0 save = lambda obj, fname, **kwargs: anyconfig.dump(obj, os.path.join("/tmp", fname), **kwargs)
*** Profile printout saved to text file u'/tmp/ips.json.lprof'.
In [7]: %lprun -T /tmp/ips.json.lprof -f save save(ipdata, "ips.bson")
Timer unit: 1e-06 s
Total time: 0.050133 s
File: <ipython-input-3-cc541fcd0a9b>
Function: <lambda> at line 1
Line # Hits Time Per Hit % Time Line Contents
==============================================================
1 1 50133 50133.0 100.0 save = lambda obj, fname, **kwargs: anyconfig.dump(obj, os.path.join("/tmp", fname), **kwargs)
*** Profile printout saved to text file u'/tmp/ips.json.lprof'.
In [8]: %lprun -T /tmp/ips.json.lprof -f save save(ipdata, "ips.yml")
Timer unit: 1e-06 s
Total time: 2.23384 s
File: <ipython-input-3-cc541fcd0a9b>
Function: <lambda> at line 1
Line # Hits Time Per Hit % Time Line Contents
==============================================================
1 1 2233843 2233843.0 100.0 save = lambda obj, fname, **kwargs: anyconfig.dump(obj, os.path.join("/tmp", fname), **kwargs)
*** Profile printout saved to text file u'/tmp/ips.json.lprof'.
In [9]: %lprun -T /tmp/ips.json.lprof -f save save(ipdata, "ips.msgpack", ac_parser="msgpack")
Timer unit: 1e-06 s
Total time: 0.051897 s
File: <ipython-input-3-cc541fcd0a9b>
Function: <lambda> at line 1
Line # Hits Time Per Hit % Time Line Contents
==============================================================
1 1 51897 51897.0 100.0 save = lambda obj, fname, **kwargs: anyconfig.dump(obj, os.path.join("/tmp", fname), **kwargs)
*** Profile printout saved to text file u'/tmp/ips.json.lprof'.
In [10]: anyconfig.list_types()
Out[10]:
['bson',
'configobj',
'ini',
'json',
'msgpack',
'properties',
'toml',
'xml',
'yaml']
In [11]:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment