Skip to content

Instantly share code, notes, and snippets.

@ionelmc

ionelmc/gist:727856

Created Dec 4, 2010
Embed
What would you like to do?
administrator@ubuntu:~/projects/sandbox$ ve-cpython/bin/python json-bench.py && ve-pypy/bin/pypy json-bench.py
Running: json-bench.py
test_cpickle
test_cpickle warmup: 3.89885687828
test_cpickle RUN: 4.03457689285
test_demjson
test_demjson warmup: 143.255517006
test_demjson RUN: 156.608139992
test_cjson
test_cjson warmup: 3.51447200775
test_cjson RUN: 3.46974015236
test_simplejson
test_simplejson warmup: 1.85804915428
test_simplejson RUN: 1.86488294601
test_repr
test_repr warmup: 3.14307999611
test_repr RUN: 3.12153887749
test_stdlib_json
test_stdlib_json warmup: 17.2829639912
test_stdlib_json RUN: 16.27425313
Running: json-bench.py
test_simplejson
test_simplejson warmup: 31.4108719826
test_simplejson RUN: 23.337460041
test_cpickle
test_cpickle warmup: 13.9072110653
test_cpickle RUN: 11.5385079384
test_demjson
test_demjson warmup: 41.6759979725
test_demjson RUN: 38.6105160713
test_repr
test_repr warmup: 5.66002011299
test_repr RUN: 5.71517109871
administrator@ubuntu:~/projects/sandbox$ cat json-bench.py
from datetime import datetime
data = [
{
'id': i,
'more': [
{
"sadf": "werf klwerjn flwerk nflkwerjn flkwerj nlkwerjn flwerkj nwer %s"%j,
"qwerqwersadf": "werfnlkwerjn flwerkj nwer %s asdf asd fsad fsad "%j,
"sadfads fasdf s": "werf klwerjn flwerk nflkwerjn flkwerj nlkwerjn werqw er qwerflwerkj nwer %s"%j,
"sadasd fasd ff": "werf klwerjn flwerk nflkwerjn flkwerj nlkwerjn flwerkj nwer asdf asdfasd %s"%j,
"sad asdf sadff": "werf klwerjn flwerk nflkwerjn flkwerj nlkwe qwer qwerrjn flwerkj nwer %s"%j,
}
for j in range(10)
],
"SADF": "WERF KLWERJN FLWERK NFLKWERJN FLKWERJ NLKWERJN FLWERKJ NWER %s"%i,
"QWERQWERSADF": "WERFNLKWERJN FLWERKJ NWER %s ASDF ASD FSAD FSAD "%i,
"SADFADS FASDF S": "WERF KLWERJN FLWER K NFLKWERJN FLKWERJ NLKWERJN WERQW ER QWERFLWERKJ NWER %s"%i,
"SADASD FASD FF": "WERF KLWERJN FLWERK NFLKWERJN FLKWERJ NLKWERJN FLWERKJ NWER ASDF ASDFASD %s"%i,
"SAD ASDF SADFF": "WERF KLWERJN FLWERK NFLKWERJN FLKWERJ NLKWE QWER QWERRJN FLWERKJ NWER %s"%i,
}
for i in range(200)
]
try:
from cjson import encode as test_cjson
except ImportError:
pass
try:
from json import dumps as test_stdlib_json
except ImportError:
pass
try:
from simplejson import dumps as test_simplejson
except ImportError:
pass
try:
from demjson import encode as test_demjson
except ImportError:
pass
test_repr = repr
try:
from cPickle import dumps as test_cpickle
except ImportError:
pass
if __name__ == "__main__":
import sys
print 'Running:', sys.argv[0]
g = dict(globals())
import timeit
for i in g:
if i.startswith('test_'):
t = timeit.Timer("%s(data)" % i, "from __main__ import data, %s" % i)
print i
print '%-020s warmup:' % i, t.timeit(200)
print '%-020s RUN:' % i, t.timeit(200)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.