plot.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. #!/usr/bin/env python
  2. import numpy as np
  3. import matplotlib.mlab as mlab
  4. import matplotlib.pyplot as plt
  5. import matplotlib.patches as mpatches
  6. # Import data from file
  7. data_cpu = np.genfromtxt('results/cpu/times.dat', dtype=None, delimiter=' ', names=['name', 'time'])
  8. data_gpu = np.genfromtxt('results/gpu/times.dat', dtype=None, delimiter=' ', names=['name', 'time'])
  9. # Generate an array as placeholder for the x axis (we need to pass from a list to an array to take advantage of range)
  10. x = range(0, 17)
  11. # Strip away the "opencl/" prefix from all the name
  12. stripped_names = []
  13. for elem in data_cpu['name']:
  14. elem = elem.replace("opencl/", "")
  15. elem = elem.replace("/ocl", "")
  16. elem = elem.replace("/OpenCL", "")
  17. stripped_names.append(elem)
  18. # Create the bar plot
  19. plt.bar(x, data_cpu['time'], width=0.5, color='b', align='edge')
  20. plt.bar(x, data_gpu['time'], width=-0.5, color='r', align='center')
  21. plt.xticks(x, stripped_names)
  22. plt.title('Execution time of the various benchmarks expressed in seconds')
  23. plt.xlabel('Benchmark')
  24. plt.ylabel('seconds')
  25. # Add some patches as legend of the colors used for the various benchmarks
  26. red_patch = mpatches.Patch(color='blue', label='Execution time for cpu')
  27. blue_patch = mpatches.Patch(color='red', label='Execution time for gpu')
  28. plt.legend(handles=[blue_patch, red_patch])
  29. plt.show()