plot.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #!/usr/bin/env python
  2. #
  3. # Copyright (c) 2018 Stefan Seefeld
  4. # All rights reserved.
  5. #
  6. # This file is part of Boost.uBLAS. It is made available under the
  7. # Boost Software License, Version 1.0.
  8. # (Consult LICENSE or http://www.boost.org/LICENSE_1_0.txt)
  9. import argparse
  10. import matplotlib.pyplot as plt
  11. import numpy as np
  12. class plot(object):
  13. def __init__(self, label, data):
  14. self.label = label
  15. self.data = data
  16. def load_file(filename):
  17. lines = open(filename, 'r').readlines()
  18. label = lines[0][1:-1].strip()
  19. lines = [l.strip() for l in lines]
  20. lines = [l.split('#', 1)[0] for l in lines]
  21. lines = [l for l in lines if l]
  22. data = [l.split() for l in lines]
  23. return plot(label, list(zip(*data)))
  24. def main(argv):
  25. parser = argparse.ArgumentParser(prog=argv[0], description='benchmark plotter')
  26. parser.add_argument('data', nargs='+', help='benchmark data to plot')
  27. parser.add_argument('--log', choices=['no', 'all', 'x', 'y'], help='use a logarithmic scale')
  28. args = parser.parse_args(argv[1:])
  29. runs = [load_file(d) for d in args.data]
  30. plt.title('Benchmark plot')
  31. plt.xlabel('size')
  32. plt.ylabel('time (s)')
  33. if args.log == 'all':
  34. plot = plt.loglog
  35. elif args.log == 'x':
  36. plot = plt.semilogx
  37. elif args.log == 'y':
  38. plot = plt.semilogy
  39. else:
  40. plot = plt.plot
  41. plots = [plot(r.data[0], r.data[1], label=r.label) for r in runs]
  42. plt.legend()
  43. plt.show()
  44. return True
  45. if __name__ == '__main__':
  46. import sys
  47. sys.exit(0 if main(sys.argv) else 1)