benchmark silo added
[c11concurrency-benchmarks.git] / silo / benchmarks / results / make_graphs-5.py
1 #!/usr/bin/env python
2
3 import matplotlib
4 import pylab as plt
5 import numpy as np
6
7 import os
8 import sys
9 import math
10
11 NAMEPAT='istc3-8-1-13%s.py'
12 def N(x):
13     return NAMEPAT % x
14
15 def split_results_by_predicate(results, pred):
16   s0, s1 = [], []
17   for res in results:
18     if pred(res):
19       s0.append(res)
20     else:
21       s1.append(res)
22   return s0, s1
23
24 FILES = (
25     (N(''), False),
26     (N('_fake_compress'), True),
27     (N(''), True),
28     (N('_newbench'), True),
29     (N('_compress'), True),
30
31     #(N('_fake_writes'), True),
32     #(N('_fake_writes_stride'), True),
33     #(N('_fake_writes_stride1'), True),
34     #(N('_log_reduce_size'), True),
35 )
36
37 def datafromfile(f, persist):
38     g, l = {}, {}
39     execfile(f, g, l)
40     res, _ = split_results_by_predicate(
41         l['RESULTS'],
42         lambda x: x[0]['persist'] if persist else not x[0]['persist'])
43     return res
44
45 if __name__ == '__main__':
46     def order_results_by_threads(results):
47         # res is list[(config, results)], change to
48         # list[(num_threads, results)]
49         def trfm(ent):
50             return (ent[0]['threads'], ent[1])
51         return map(trfm, results)
52
53     def extract_result_position(k, res):
54         if type(res) == list:
55             return [x[k] for x in res]
56         return res[k]
57
58     def extract_throughput(results, persist):
59         def trfm(ent):
60             return (ent[0], extract_result_position(0 if not persist else 1, ent[1]))
61         return map(trfm, results)
62
63     def extract_latency(results, persist):
64         def trfm(ent):
65             return (ent[0], extract_result_position(2 if not persist else 3, ent[1]))
66         return map(trfm, results)
67
68     def filter_name(results, name):
69         def match(ent):
70             return ent[0]['name'] == name
71         return [x for x in results if match(x)]
72
73     def XX(x):
74         return [e[0] for e in x]
75
76     def perturb(x):
77         return [np.random.normal(loc=0.0, scale=0.2) + e for e in x]
78
79     def scalaradd(x, s):
80         return [e + s for e in x]
81
82     def scale(x, s):
83         return [e / s for e in x]
84
85     def median(x): return sorted(x)[len(x)/2]
86
87     def percorify(x):
88         return [ (e[0], [ee/e[0] for ee in e[1]]) for e in x ]
89
90     def YY(x):
91         def checked(e):
92             if type(e) == list:
93                 return median(e)
94             return e
95         return [checked(e[1]) for e in x]
96
97     def YYPC(x):
98         def checked(e):
99             if type(e) == list:
100                 return median(e)
101             return e
102         return [checked(e[1])/float(e[0]) for e in x]
103
104     def YERR(x):
105         ypts = [e[1] for e in x]
106         ymins = np.array([min(x) for x in ypts])
107         ymaxs = np.array([max(x) for x in ypts])
108         ymid = np.array([median(x) for x in ypts])
109         yerr=np.array([ymid - ymins, ymaxs - ymid])
110         return yerr
111
112     def YERRPC(x):
113         ypts = [[ee/float(e[0]) for ee in e[1]] for e in x]
114         ymins = np.array([min(x) for x in ypts])
115         ymaxs = np.array([max(x) for x in ypts])
116         ymid = np.array([median(x) for x in ypts])
117         yerr=np.array([ymid - ymins, ymaxs - ymid])
118         return yerr
119
120     def nameit(x):
121         fname, persist = x
122         fname = fname.replace('istc3-8-1-13', '').replace('.py', '')
123         if not fname:
124             return 'base-persist' if persist else 'base'
125         return fname
126
127     fig, fig1 = plt.figure(), plt.figure()
128     ax, ax1 = fig.add_subplot(111), fig1.add_subplot(111)
129
130     from matplotlib.font_manager import FontProperties
131     fontP = FontProperties()
132     fontP.set_size('small')
133
134     off = 0.0
135     for fname, persist in FILES:
136         res = datafromfile(fname, persist)
137         res = order_results_by_threads(res)
138         throughput = extract_throughput(res, persist)
139         percorethroughput = percorify(throughput)
140         print percorethroughput
141         ax.errorbar(scalaradd(XX(throughput), off), YY(percorethroughput), yerr=YERR(percorethroughput))
142         off += 0.1
143
144     ax.legend(map(nameit, FILES), loc='lower right', prop=fontP)
145     ax.set_xlabel('threads')
146     ax.set_ylabel('throughput (txns/sec/core)')
147     ax.set_ylim([0, 32000])
148     fig.savefig('istc3-8-1-13_summary.pdf')