import cPickle as pickle
with open('result.db') as f:
data = f.read()
RES = pickle.loads(data)
from IPython.display import HTML
from collections import defaultdict
SERIES = []
options = ('', '-i', '-v')
commands = ('grep', 'ack', 'ag')
xns = ('en', 'cn')
for xn in xns:
for word in RES[xn]:
for option in options:
series = []
for command in commands:
_res = {}
w_value = RES[xn][word]
for size in w_value:
res = w_value[size]
_r = res[command][option]
_res[size] = _r
v = [i[1] for i in sorted(
_res.iteritems(), key=lambda x:int(x[0]))
]
series.append({
'name': command,
'data': v
})
subtitle = '{0} {1} {2}'.format(xn, word, option)
SERIES.append((subtitle, series))
div_tmpl = '<div id="{0}" style="min-width: 400px; height: 400px; margin: 0 auto"></div>'
div = '\n'.join([div_tmpl.format("chart%d" % index) for index in range(len(SERIES))])
js_tmpl = 'setTimeout("do_chart(\'{0}\', \'{1}\', {2})", 50)'
js = ';\n'.join([js_tmpl.format("chart%d" % index, series[0], series[1]) for index, series in enumerate(SERIES)])
HTML('''
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>
%s
<script>
do_chart = function(chartid, subtitle, series) {
$("#" + chartid).highcharts({
chart: {
type: 'line',
marginRight: 130,
marginBottom: 25
},
title: {
text: 'grep, ack, ag search benchmarks',
x: -20
},
subtitle: {
text: subtitle,
x: -20
},
xAxis: {
categories: [1, 10, 100, 500, 1024, 5072]
},
yAxis: {
title: {
text: 'time'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
valueSuffix: ''
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -10,
y: 100,
borderWidth: 0
},
series: series
});
}
%s
</script>
''' % (div, js))