on 0.3.2.9 help sign in
typeable/aeson/benchmarks/bench-parse.py
50 lines 1.6 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)
7def run(count, filename):
8 print ' %s :: %s times' % (filename, count)
9 p = subprocess.Popen(['./AesonParse', str(count), filename],
10 stdout=subprocess.PIPE)
11 output = p.stdout.read()
12 p.wait()
13 m = result_re.search(output)
14 if not m:
15 print >> sys.stderr, 'run gave confusing output!?'
16 sys.stderr.write(output)
17 return
18 else:
19 #sys.stdout.write(output)
20 pass
21 good, elapsed = m.groups()
22 good, elapsed = int(good), float(elapsed)
23 st = os.stat(filename)
24 parses_per_second = good / elapsed
25 mb_per_second = st.st_size * parses_per_second / 1048576
26 print (' %.3f seconds, %d parses/sec, %.3f MB/sec' %
27 (elapsed, parses_per_second, mb_per_second))
28 return parses_per_second, mb_per_second, st.st_size, elapsed
30def runtimes(count, filename, times=1):
31 for i in xrange(times):
32 yield run(count, filename)
34info = '''
35json-data/twitter1.json 60000
36json-data/twitter10.json 13000
37json-data/twitter20.json 7500
38json-data/twitter50.json 2500
39json-data/twitter100.json 1000
40json-data/jp10.json 4000
41json-data/jp50.json 1200
42json-data/jp100.json 700
43'''
45for i in info.strip().splitlines():
46 name, count = i.split()
47 best = sorted(runtimes(int(count), name, times=3), reverse=True)[0]
48 parses_per_second, mb_per_second, size, elapsed = best
49 print ('%.1f KB: %d msg\\/sec (%.1f MB\\/sec)' %
50 (size / 1024.0, int(round(parses_per_second)), mb_per_second))