summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRune Halvorsen <runefh@gmail.com>2010-04-10 12:39:54 +0200
committerRune Halvorsen <runefh@gmail.com>2010-04-10 12:39:54 +0200
commitf7b0fdd9614234800438e4cac24a4e6e4719c4bf (patch)
tree72c00119718694585cf5604d58414490137207a2
parentf6a3e5c60f83bf968fd4b23a51f33d5897601621 (diff)
downloadanyjson-f7b0fdd9614234800438e4cac24a4e6e4719c4bf.tar.gz
Added serialization testing, not just parsing
-rw-r--r--tests/benchmark.py39
1 files changed, 23 insertions, 16 deletions
diff --git a/tests/benchmark.py b/tests/benchmark.py
index 652f43b..1a02979 100644
--- a/tests/benchmark.py
+++ b/tests/benchmark.py
@@ -82,37 +82,40 @@ def load_external_json():
def do_benchmark(impspec, json, runs=10):
- modulename, funcname = impspec
+ modulename, parsename, emitname = impspec
try:
__import__(modulename)
mod = sys.modules[modulename]
- fun = getattr(mod, funcname)
+ reads = getattr(mod, parsename)
+ dumps = getattr(mod, emitname)
except:
return None
start = time.time()
for n in xrange(runs):
- data = fun(json)
+ data = reads(json)
- end = time.time()
+ readtime = time.time() - start
- return end-start
+ start = time.time()
+ for n in xrange(runs):
+ data = dumps(data)
+ return readtime, time.time() - start # tuple (readtime, writetime)
-modules = [("json", "loads"),
- ("simplejson", "loads"),
- ("yajl", "loads"),
- ("cjson", "decode"),
- ("django.utils.simplejson", "loads"),
- ("jsonpickle", "decode"),
- ("jsonlib", "read"),
- ("jsonlib2", "read"),
+modules = [("json", "loads", "dumps"),
+ ("simplejson", "loads", "dumps"),
+ ("yajl", "loads", "dumps"),
+ ("cjson", "decode", "encode"),
+ ("django.utils.simplejson", "loads", "dumps"),
+ ("jsonpickle", "decode", "encode"),
+ #("jsonlib", "read", "write"),
+ ("jsonlib2", "read", "write"),
# ("demjson", "decode"), terribly slow. wont include it
]
-
if len(sys.argv) > 1 and sys.argv[1] == "--download":
load_external_json()
@@ -128,9 +131,13 @@ for e in modules:
no_res = set([e for e in res if e[1] is None])
res = list(set(res) - no_res)
-res.sort(lambda a,b: cmp(sum(a[1:]), sum(b[1:])))
+res = [(e[0], sum(map(lambda x:x[0], e[1:])), sum(map(lambda x:x[1], e[1:]))) for e in res]
+
+res.sort(lambda a,b: cmp((a[1]+a[2]), b[1]+b[2]))
+print "Total Read Write Implementation"
+print "-----------------------------------"
for e in res:
- print "%.3f %s" % (sum(e[1:]), e[0])
+ print "%.3f %.3f %.3f %s" % (e[1]+e[2], e[1], e[2], e[0])
for e in no_res:
print "Not installed:", e[0]