Skip to content

Commit

Permalink
add ujson to shootout; it's neck-and-neck with tnetstring
Browse files Browse the repository at this point in the history
  • Loading branch information
rfk committed Apr 2, 2011
1 parent 43e9598 commit 6333e56
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tools/shootout.py
Expand Up @@ -3,6 +3,7 @@

import cjson
import yajl
import ujson
import tnetstring

from tnetstring.tests.test_format import FORMAT_EXAMPLES, get_random_object
Expand All @@ -13,6 +14,7 @@ def add_test(v):
try:
assert cjson.decode(cjson.encode(v)) == v
assert yajl.loads(yajl.dumps(v)) == v
assert ujson.loads(ujson.dumps(v)) == v
except Exception:
pass
else:
Expand All @@ -39,22 +41,35 @@ def thrash_yajl():
assert yajl.loads(json) == obj
assert yajl.loads(yajl.dumps(obj)) == obj

def thrash_ujson():
for obj, tns, json in TESTS:
assert ujson.loads(json) == obj
assert ujson.loads(ujson.dumps(obj)) == obj


if __name__ == "__main__":
import timeit
t1 = timeit.Timer("thrash_tnetstring()",
"from shootout import thrash_tnetstring")
t1 = min(t1.repeat(number=10000))
print "tnetstring", t1

t2 = timeit.Timer("thrash_cjson()",
"from shootout import thrash_cjson")
t2 = min(t2.repeat(number=10000))
print "cjson:", t2
print "speedup: ", round((t2 - t1) / (t2) * 100,2), "%"

t3 = timeit.Timer("thrash_yajl()",
"from shootout import thrash_yajl")
t3 = min(t3.repeat(number=10000))
print "yajl:", t3
print "speedup: ", round((t3 - t1) / (t3) * 100,2), "%"

t4 = timeit.Timer("thrash_ujson()",
"from shootout import thrash_ujson")
t4 = min(t4.repeat(number=10000))
print "ujson:", t4
print "speedup: ", round((t4 - t1) / (t4) * 100,2), "%"


0 comments on commit 6333e56

Please sign in to comment.