plot.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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/total.dat', dtype=None, delimiter=',', names=['name', 'time', 'power'])
  8. data_gpu_primary = np.genfromtxt('results/gpu-primary/total.dat', dtype=None, delimiter=',', names=['name', 'time', 'power'])
  9. data_gpu_secondary = np.genfromtxt('results/gpu-secondary/total.dat', dtype=None, delimiter=',', names=['name', 'time', 'power'])
  10. # Generate an array as placeholder for the x axis (we need to pass from a list to an array to take advantage of range)
  11. x = range(0, 17)
  12. # Strip away the "opencl/" prefix from all the name
  13. stripped_names = []
  14. for elem in data_cpu['name']:
  15. elem = elem.replace("opencl/", "")
  16. elem = elem.replace("/ocl", "")
  17. elem = elem.replace("/OpenCL", "")
  18. stripped_names.append(elem)
  19. # Create the bar plot for the time values
  20. plt.bar(x, data_cpu['time'], width=0.3, color='b', align='edge')
  21. plt.bar(x, data_gpu_primary['time'], width=-0.3, color='r', align='center')
  22. plt.bar(x, data_gpu_secondary['time'], width=-0.3, color='g', align='edge')
  23. plt.xticks(x, stripped_names)
  24. plt.title('Execution time of the various benchmarks expressed in seconds')
  25. plt.xlabel('Benchmark')
  26. plt.ylabel('seconds')
  27. # Add some patches as legend of the colors used for the various benchmarks
  28. red_patch = mpatches.Patch(color='blue', label='Execution time for cpu')
  29. blue_patch = mpatches.Patch(color='red', label='Execution time for gpu(4 core)')
  30. green_patch = mpatches.Patch(color='green', label='Execution time for gpu(2 core)')
  31. plt.legend(handles=[red_patch, blue_patch, green_patch])
  32. plt.savefig('times.pdf')
  33. plt.show()
  34. # Create the bar plot for the power values
  35. plt.bar(x, data_cpu['power'], width=0.3, color='b', align='edge')
  36. plt.bar(x, data_gpu_primary['power'], width=-0.3, color='r', align='center')
  37. plt.bar(x, data_gpu_secondary['power'], width=-0.3, color='g', align='edge')
  38. plt.xticks(x, stripped_names)
  39. plt.title('Power consumption of the various benchmarks expressed in Watt/hour')
  40. plt.xlabel('Benchmark')
  41. plt.ylabel('Watt/hour')
  42. # Add some patches as legend of the colors used for the various benchmarks
  43. red_patch = mpatches.Patch(color='blue', label='Power consumption for cpu')
  44. blue_patch = mpatches.Patch(color='red', label='Power consumption for gpu(4 core)')
  45. green_patch = mpatches.Patch(color='green', label='Execution time for gpu(2 core)')
  46. plt.legend(handles=[red_patch, blue_patch, green_patch])
  47. plt.savefig('power.pdf')
  48. plt.show()