forked from jamesls/semidbm
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmakegraphs
More file actions
executable file
·77 lines (67 loc) · 2.56 KB
/
Copy pathmakegraphs
File metadata and controls
executable file
·77 lines (67 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python
# This script is used to generate fancy charts and text tables
# from a .json file produced via the '-r' argument of scripts/benchmark.
import os
import sys
import json
import optparse
# I don't expect anyone else to run this script, but OrderedDict
# requires python2.7.
from collections import OrderedDict
import numpy.numarray as na
from matplotlib import pyplot as p
import matplotlib
import texttable
def generate_charts(results, benchmark_to_use, results_filename):
labels = results['dbms']
font = {'size' : 7}
matplotlib.rc('font', **font)
for name, benchmark in results['benchmarks'].iteritems():
data = [b[benchmark_to_use] for b in benchmark]
title = name
title += ('(numkeys=%(num_keys)s,keysize=%(key_size_bytes)s,'
'valsize=%(value_size_bytes)s)' % results)
xlocations = na.array(range(len(data)))+0.5
width = 0.5
p.gcf().set_size_inches(5, 5)
p.bar(xlocations, data, width=width)
ymax = int(max(data)) + 1
p.yticks(range(0, ymax, ymax / 10))
p.ylim(0, ymax)
p.xticks(xlocations + width / 2, labels)
p.xlim(0, xlocations[-1] + width * 2)
p.ylabel(benchmark_to_use)
p.title(title)
p.gca().get_xaxis().tick_bottom()
p.gca().get_yaxis().tick_left()
p.savefig('docs/img/' + '%s_%s' %
(os.path.splitext(results_filename)[0], name))
p.close('all')
def generate_table(results, metric_to_use):
dbms = results['dbms']
title = ('n=%(num_keys)s,k=%(key_size_bytes)s,'
'v=%(value_size_bytes)s' % results)
t = texttable.Texttable(max_width=120)
t.set_cols_align(['l'] + ['r' for i in xrange(len(dbms))])
t.add_rows([
[title] + dbms,
])
for name, benchmark in results['benchmarks'].iteritems():
t.add_row([name] + [b[metric_to_use] for b in benchmark])
print t.draw()
def main():
parser = optparse.OptionParser()
parser.add_option('-t', '--table', action="store_true", default=False)
parser.add_option('-c', '--chart', action="store_true", default=False)
parser.add_option('-b', '--benchmark', default="ops_per_second")
opts, args = parser.parse_args()
if len(args) != 1:
sys.stderr.write("Supply the name of the .json report.")
sys.exit(1)
results = json.load(open(args[0]), object_pairs_hook=OrderedDict)
if opts.chart:
generate_charts(results, opts.benchmark, args[0])
if opts.table:
generate_table(results, opts.benchmark)
if __name__ == '__main__':
main()