1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- #!/usr/bin/env python
- import numpy as np
- import matplotlib.mlab as mlab
- import matplotlib.pyplot as plt
- import matplotlib.patches as mpatches
- # Import data from file
- data_cpu = np.genfromtxt('results/cpu/average.csv', dtype=None, delimiter=',', names=['name', 'time', 'power'])
- data_gpu_primary = np.genfromtxt('results/gpu-primary/average.csv', dtype=None, delimiter=',', names=['name', 'time', 'power'])
- data_gpu_secondary = np.genfromtxt('results/gpu-secondary/average.csv', dtype=None, delimiter=',', names=['name', 'time', 'power'])
- # We construct a set in which we insert each benchmark name once
- nameset = set()
- names = data_cpu['name']
- for name in names:
- nameset.add(name)
- # Generate an array as placeholder for the x axis (we need to pass from a list to an array to take advantage of range)
- x = range(0, 17)
- # Strip away the "opencl/" prefix from all the name
- stripped_names = []
- for elem in data_cpu['name']:
- elem = elem.replace("opencl/", "")
- elem = elem.replace("/ocl", "")
- elem = elem.replace("/OpenCL", "")
- stripped_names.append(elem)
- # Create the bar plot for the time values
- plt.bar(x, data_cpu['time'], width=0.3, color='b', align='edge')
- plt.bar(x, data_gpu_primary['time'], width=-0.3, color='r', align='center')
- plt.bar(x, data_gpu_secondary['time'], width=-0.3, color='g', align='edge')
- plt.xticks(x, stripped_names)
- plt.title('Execution time of the various benchmarks expressed in seconds')
- plt.xlabel('Benchmark')
- plt.ylabel('seconds')
- # Add some patches as legend of the colors used for the various benchmarks
- red_patch = mpatches.Patch(color='blue', label='Execution time for cpu')
- blue_patch = mpatches.Patch(color='red', label='Execution time for gpu(4 core)')
- green_patch = mpatches.Patch(color='green', label='Execution time for gpu(2 core)')
- plt.legend(handles=[red_patch, blue_patch, green_patch])
- # Save the obtained plot on file
- plt.savefig('times.pdf')
- plt.show()
- # Create the bar plot for the power values
- plt.bar(x, data_cpu['power'], width=0.3, color='b', align='edge')
- plt.bar(x, data_gpu_primary['power'], width=-0.3, color='r', align='center')
- plt.bar(x, data_gpu_secondary['power'], width=-0.3, color='g', align='edge')
- plt.xticks(x, stripped_names)
- plt.title('Power consumption of the various benchmarks expressed in Watt/hour')
- plt.xlabel('Benchmark')
- plt.ylabel('Watt/hour')
- # Add some patches as legend of the colors used for the various benchmarks
- red_patch = mpatches.Patch(color='blue', label='Power consumption for cpu')
- blue_patch = mpatches.Patch(color='red', label='Power consumption for gpu(4 core)')
- green_patch = mpatches.Patch(color='green', label='Execution time for gpu(2 core)')
- plt.legend(handles=[red_patch, blue_patch, green_patch])
- # Save the obtained plot on file
- plt.savefig('power.pdf')
- plt.show()
|