Bryan O'Sullivan avatar Bryan O'Sullivan committed c967bc9

Add benchmark running script

Comments (0)

Files changed (1)

benchmarks/bench-parse.py

+#!/usr/bin/env python
+
+import os, re, subprocess, sys
+
+result_re = re.compile(r'^\s*(\d+) good, (\d+\.\d+)s$', re.M)
+
+def run(count, filename):
+    print '    %s :: %s times' % (filename, count)
+    p = subprocess.Popen(['./AesonParse', str(count), filename],
+                         stdout=subprocess.PIPE)
+    output = p.stdout.read()
+    p.wait()
+    m = result_re.search(output)
+    if not m:
+        print >> sys.stderr, 'run gave confusing output!?'
+        sys.stderr.write(output)
+        return
+    else:
+        #sys.stdout.write(output)
+        pass
+    good, elapsed = m.groups()
+    good, elapsed = int(good), float(elapsed)
+    st = os.stat(filename)
+    parses_per_second = good / elapsed
+    mb_per_second = st.st_size * parses_per_second / 1048576
+    print ('      %.3f seconds, %d parses/sec, %.3f MB/sec' %
+           (elapsed, parses_per_second, mb_per_second))
+    return parses_per_second, mb_per_second, st.st_size, elapsed
+
+def runtimes(count, filename, times=1):
+    for i in xrange(times):
+        yield run(count, filename)
+
+info = '''
+json-data/twitter1.json   60000
+json-data/twitter10.json  13000
+json-data/twitter20.json   7500
+json-data/twitter50.json   2500
+json-data/twitter100.json  1000
+json-data/jp10.json        4000
+json-data/jp20.json        3000
+json-data/jp50.json        1200
+json-data/jp100.json        700
+'''
+
+for i in info.strip().splitlines():
+    name, count = i.split()
+    best = sorted(runtimes(int(count), name, times=3), reverse=True)[0]
+    parses_per_second, mb_per_second, size, elapsed = best
+    print ('%.1f KB: %d msg\\/sec (%.1f MB\\/sec)' %
+           (size / 1024.0, int(round(parses_per_second)), mb_per_second))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.