summaryrefslogtreecommitdiff
path: root/codec-speed
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2011-04-23 18:09:44 +0100
committerLars Wirzenius <liw@liw.fi>2011-04-23 18:09:44 +0100
commitb160327dbbd0130432061fc1a521b3f2a70317c3 (patch)
tree5659ac0790f8c000b53c7d89686c61d8642b2943 /codec-speed
parent03323cc03e6dfdbc9c30ab6acde255bd4f82f495 (diff)
downloadlarch-b160327dbbd0130432061fc1a521b3f2a70317c3.tar.gz
Make codec-speed optionally add stuff to a CSV file.
Diffstat (limited to 'codec-speed')
-rwxr-xr-xcodec-speed72
1 files changed, 60 insertions, 12 deletions
diff --git a/codec-speed b/codec-speed
index fd70235..671939c 100755
--- a/codec-speed
+++ b/codec-speed
@@ -17,6 +17,9 @@
import cliapp
import cProfile
+import csv
+import os
+import subprocess
import sys
import time
@@ -62,24 +65,32 @@ class CodecBenchmark(cliapp.Application):
index = larch.IndexNode(42, keys, index_values)
encoded_index = codec.encode_index(index)
+
# Measure and report.
print 'num_operations: %d' % n
- self.measure(n, len(encoded_leaf),
- lambda: codec.leaf_size(keys, leaf_values),
- do_profile, 'leaf_size')
- self.measure(n, len(encoded_leaf), lambda: codec.encode_leaf(leaf),
- do_profile, 'encode_leaf')
- self.measure(n, len(encoded_leaf), lambda: codec.decode(encoded_leaf),
- do_profile, 'decode_leaf')
- self.measure(n, len(encoded_index), lambda: codec.encode_index(index),
- do_profile, 'encode_index')
- self.measure(n, len(encoded_index),
- lambda: codec.decode_index(encoded_index),
- do_profile, 'decode_index')
+ leaf_size = self.measure(n, len(encoded_leaf),
+ lambda: codec.leaf_size(keys, leaf_values),
+ do_profile, 'leaf_size')
+ encode_leaf = self.measure(n, len(encoded_leaf),
+ lambda: codec.encode_leaf(leaf),
+ do_profile, 'encode_leaf')
+ decode_leaf = self.measure(n, len(encoded_leaf),
+ lambda: codec.decode(encoded_leaf),
+ do_profile, 'decode_leaf')
+ encode_index = self.measure(n, len(encoded_index),
+ lambda: codec.encode_index(index),
+ do_profile, 'encode_index')
+ decode_index = self.measure(n, len(encoded_index),
+ lambda: codec.decode_index(encoded_index),
+ do_profile, 'decode_index')
if do_profile:
print 'View *.prof with ./viewprof for profiling results.'
+ if self.settings['csv']:
+ self.append_csv(n, leaf_size, encode_leaf, decode_leaf,
+ encode_index, decode_index)
+
def measure(self, n, unit_size, func, do_profile, profname):
def helper():
for i in range(n):
@@ -106,6 +117,43 @@ class CodecBenchmark(cliapp.Application):
fmt = '%12s %6.0f MiB/s (CPU) %6.0f MiBs (wall)'
print fmt % (profname, cpu_speed, wall_speed)
+ return cpu_speed
+
+ def append_csv(self, keys, leaf_size, encode_leaf, decode_leaf,
+ encode_index, decode_index):
+ write_title = not os.path.exists(self.settings['csv'])
+ f = open(self.settings['csv'], 'a')
+ self.writer = csv.writer(f, lineterminator='\n')
+ if write_title:
+ self.writer.writerow(('revno',
+ 'keys',
+ 'leaf_size (MiB/s)',
+ 'encode_leaf (MiB/s)',
+ 'decode_leaf (MiB/s)',
+ 'encode_index (MiB/s)',
+ 'decode_index (MiB/s)'))
+
+ if os.path.exists('.bzr'):
+ p = subprocess.Popen(['bzr', 'revno'], stdout=subprocess.PIPE)
+ out, err = p.communicate()
+ if p.returncode != 0:
+ raise cliapp.AppException('bzr failed')
+ revno = out.strip()
+ else:
+ revno = '?'
+
+ self.writer.writerow((revno,
+ keys,
+ self.format(leaf_size),
+ self.format(encode_leaf),
+ self.format(decode_leaf),
+ self.format(encode_index),
+ self.format(decode_index)))
+ f.close()
+
+ def format(self, value):
+ return '%.1f' % value
+
if __name__ == '__main__':
CodecBenchmark().run()