1#!/usr/bin/python 2 3# Copyright (c) 2014 Kyle Lutz <kyle.r.lutz@gmail.com> 4# Distributed under the Boost Software License, Version 1.0 5# See accompanying file LICENSE_1_0.txt or copy at 6# http://www.boost.org/LICENSE_1_0.txt 7# 8# See http://boostorg.github.com/compute for more information. 9 10import os 11import sys 12import pylab 13 14from perf import run_benchmark 15 16fignum = 0 17 18def plot_to_file(report, filename): 19 global fignum 20 fignum += 1 21 pylab.figure(fignum) 22 23 run_to_label = { 24 "stl" : "C++ STL", 25 "thrust" : "Thrust", 26 "compute" : "Boost.Compute", 27 "bolt" : "Bolt" 28 } 29 30 for run in sorted(report.samples.keys()): 31 x = [] 32 y = [] 33 34 for sample in report.samples[run]: 35 x.append(sample[0]) 36 y.append(sample[1]) 37 38 pylab.loglog(x, y, marker='o', label=run_to_label[run]) 39 40 pylab.xlabel("Size") 41 pylab.ylabel("Time (ms)") 42 pylab.legend(loc='upper left') 43 pylab.savefig(filename) 44 45if __name__ == '__main__': 46 sizes = [pow(2, x) for x in range(10, 26)] 47 algorithms = [ 48 "accumulate", 49 "count", 50 "inner_product", 51 "merge", 52 "partial_sum", 53 "partition", 54 "reverse", 55 "rotate", 56 "saxpy", 57 "sort", 58 "unique", 59 ] 60 61 try: 62 os.mkdir("perf_plots") 63 except OSError: 64 pass 65 66 for algorithm in algorithms: 67 print("running '%s'" % (algorithm)) 68 report = run_benchmark(algorithm, sizes, ["stl", "thrust", "bolt"]) 69 plot_to_file(report, "perf_plots/%s_time_plot.png" % algorithm) 70 71