[pypy-commit] benchmarks default: add a simple json benchmark

fijal noreply at buildbot.pypy.org
Thu Oct 20 18:37:13 CEST 2011


Author: Maciej Fijalkowski <fijall at gmail.com>
Branch: 
Changeset: r147:a561cae55462
Date: 2011-10-20 18:34 +0200
http://bitbucket.org/pypy/benchmarks/changeset/a561cae55462/

Log:	add a simple json benchmark

diff --git a/benchmarks.py b/benchmarks.py
--- a/benchmarks.py
+++ b/benchmarks.py
@@ -54,7 +54,8 @@
 
 for name in ['float', 'nbody_modified', 'meteor-contest', 'fannkuch',
              'spectral-norm', 'chaos', 'telco', 'go', 'pyflate-fast',
-             'raytrace-simple', 'crypto_pyaes', 'bm_mako', 'bm_chameleon']:
+             'raytrace-simple', 'crypto_pyaes', 'bm_mako', 'bm_chameleon',
+             'json_bench']:
     _register_new_bm(name, name, globals(), **opts.get(name, {}))
 for name in ['names', 'iteration', 'tcp', 'pb']:#, 'web', 'accepts']:
     iteration_scaling = 1.0
diff --git a/own/json_bench.py b/own/json_bench.py
new file mode 100644
--- /dev/null
+++ b/own/json_bench.py
@@ -0,0 +1,33 @@
+import time
+import json
+
+# execution runtime per test case
+TARGET_RUNTIME = 10
+
+EMPTY = ({}, 200000)
+SIMPLE = ({'key1': 0, 'key2': True, 'key3': 'value', 'key4': 'foo', 'key5': 'string'}, 100000)
+NESTED = ({'key1': 0, 'key2': SIMPLE[0], 'key3': 'value', 'key4': SIMPLE[0], 'key5': SIMPLE[0], u'key': u'\u0105\u0107\u017c'}, 100000)
+HUGE = ([NESTED[0]] * 1000, 100)
+
+cases = ['EMPTY', 'SIMPLE', 'NESTED', 'HUGE']
+
+def main(n):
+    l = []
+    for i in range(n):
+        t0 = time.time()
+        for case in cases:
+            data, count = globals()[case]
+            for i in range(count):
+                json.dumps(data)
+        l.append(time.time() - t0)
+    return l
+
+if __name__ == '__main__':
+    import util, optparse
+    parser = optparse.OptionParser(
+        usage="%prog [options]",
+        description="Test the performance of the Go benchmark")
+    util.add_standard_options_to(parser)
+    options, args = parser.parse_args()
+
+    util.run_benchmark(options, options.num_runs, main)


More information about the pypy-commit mailing list