perfdoc.py 1.6 KB

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