Betweenness Centrality benchmark

1. Вычитываем результат бенчмарка


In [1]:
!head -n3 bench.json


{"type": "serial", "n": 500, "p": 0.0400802, "repeat": 0, "sec": 0.670891}
{"type": "parallel", "n": 500, "p": 0.0400802, "num_threads": 2, "repeat": 0, "sec": 0.360089}
{"type": "parallel", "n": 500, "p": 0.0400802, "num_threads": 3, "repeat": 0, "sec": 0.246948}

In [2]:
import json

graphics = {}
with open("bench.json") as infile:
    for line in infile:
        r = json.loads(line)
        k = (r["type"], r.get("num_threads", 1), r["n"])
        
        graphics.setdefault(k, 0.)
        graphics[k] += r["sec"]
        

        
x_axis = range(500, 5001, 500)
y_serial = [graphics[('serial', 1, _)] / 3. for _ in x_axis]
y_parallels = {thrd: [graphics[('parallel', thrd, _)] / 3. for _ in x_axis] for thrd in range(2, 9)}

2. Строим графики


In [3]:
import plotly.offline as py
import plotly.graph_objs as go

py.init_notebook_mode()
data = [go.Scatter(x = x_axis,
                   y = y_serial,
                   mode = 'lines+markers',
                   name = 'Serail')]

for k in y_parallels:
    data.append(go.Scatter(x = x_axis,
                           y = y_parallels[k],
                           mode = 'lines+markers',
                           name = 'Parallel, {} threads'.format(k)))
    
layout = dict(title='BetweennessCentrality Benchmark', xaxis=dict(title='Nodes num'), yaxis=dict(title="Seconds"))
py.iplot(go.Figure(data=data, layout=layout))