summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/compute/perf/perfdoc.py
blob: e9c60362f0c5043b083069bc10c031dc4ae77765 (plain)
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
#!/usr/bin/python

# Copyright (c) 2014 Kyle Lutz <kyle.r.lutz@gmail.com>
# Distributed under the Boost Software License, Version 1.0
# See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt
#
# See http://boostorg.github.com/compute for more information.

import os
import sys
import pylab

from perf import run_benchmark

fignum = 0

def plot_to_file(report, filename):
    global fignum
    fignum += 1
    pylab.figure(fignum)

    run_to_label = {
        "stl" : "C++ STL",
        "thrust" : "Thrust",
        "compute" : "Boost.Compute",
        "bolt" : "Bolt"
    }

    for run in sorted(report.samples.keys()):
        x = []
        y = []

        for sample in report.samples[run]:
            x.append(sample[0])
            y.append(sample[1])

        pylab.loglog(x, y, marker='o', label=run_to_label[run])

    pylab.xlabel("Size")
    pylab.ylabel("Time (ms)")
    pylab.legend(loc='upper left')
    pylab.savefig(filename)

if __name__ == '__main__':
    sizes = [pow(2, x) for x in range(10, 26)]
    algorithms = [
        "accumulate",
        "count",
        "inner_product",
        "merge",
        "partial_sum",
        "partition",
        "reverse",
        "rotate",
        "saxpy",
        "sort",
        "unique",
    ]

    try:
        os.mkdir("perf_plots")
    except OSError:
        pass

    for algorithm in algorithms:
        print("running '%s'" % (algorithm))
        report = run_benchmark(algorithm, sizes, ["stl", "thrust", "bolt"])
        plot_to_file(report, "perf_plots/%s_time_plot.png" % algorithm)