on 0.11.3.0 help sign in
typeable/aeson/benchmarks/bench-parse.py
56 lines 1.8 kB history raw
1#!/usr/bin/env python
3import os, re, subprocess, sys
5result_re = re.compile(r'^\s*(\d+) good, (\d+\.\d+)s$', re.M)
7if len(sys.argv) > 1:
8 parser_exe = sys.argv[1]
9else:
10 parser_exe = ('dist/build/aeson-benchmark-aeson-parse/' +
11 'aeson-benchmark-aeson-parse')
13def run(count, filename):
14 print ' %s :: %s times' % (filename, count)
15 p = subprocess.Popen([parser_exe, '65536', str(count), filename],
16 stdout=subprocess.PIPE)
17 output = p.stdout.read()
18 p.wait()
19 m = result_re.search(output)
20 if not m:
21 print >> sys.stderr, 'run gave confusing output!?'
22 sys.stderr.write(output)
23 return
24 else:
25 #sys.stdout.write(output)
26 pass
27 good, elapsed = m.groups()
28 good, elapsed = int(good), float(elapsed)
29 st = os.stat(filename)
30 parses_per_second = good / elapsed
31 mb_per_second = st.st_size * parses_per_second / 1048576
32 print (' %.3f seconds, %d parses/sec, %.3f MB/sec' %
33 (elapsed, parses_per_second, mb_per_second))
34 return parses_per_second, mb_per_second, st.st_size, elapsed
36def runtimes(count, filename, times=1):
37 for i in xrange(times):
38 yield run(count, filename)
40info = '''
41json-data/twitter1.json 60000
42json-data/twitter10.json 13000
43json-data/twitter20.json 7500
44json-data/twitter50.json 2500
45json-data/twitter100.json 1000
46json-data/jp10.json 4000
47json-data/jp50.json 1200
48json-data/jp100.json 700
49'''
51for i in info.strip().splitlines():
52 name, count = i.split()
53 best = sorted(runtimes(int(count), name, times=3), reverse=True)[0]
54 parses_per_second, mb_per_second, size, elapsed = best
55 print ('%.1f KB: %d msg\\/sec (%.1f MB\\/sec)' %
56 (size / 1024.0, int(round(parses_per_second)), mb_per_second))