2024-heraklion-parallel-python/exercises/exerciseA/plot.py

29 lines
773 B
Python
Raw Normal View History

2024-08-29 11:19:39 +02:00
import os
import numpy as np
import matplotlib.pyplot as plt
# IO: This loads the timings for you
threads, timings = [], []
for file in os.listdir('timings'):
with open(f'timings/{file}', 'r') as f:
n, t = f.read().strip().split(',')
threads.append(int(n))
timings.append(float(t))
threads = np.array(threads)
timings = np.array(timings)
2024-08-30 11:27:32 +02:00
timings /= timings[np.where(threads == 1)[0][0]]
2024-08-29 11:19:39 +02:00
print('This is the data I loaded: threads =', threads, ', timings =',timings)
fig, axs = plt.subplots()
2024-08-30 11:09:47 +02:00
2024-08-29 11:19:39 +02:00
# Remember to label your axis
# Feel free to make it pretty
2024-08-30 11:09:47 +02:00
axs.plot(threads, timings, '*')
axs.set_xlabel('number of threads')
2024-08-30 11:27:32 +02:00
axs.set_ylabel('relative processing time to single threading')
2024-08-30 11:09:47 +02:00
2024-08-29 11:19:39 +02:00
2024-08-30 11:27:32 +02:00
plt.savefig('threads_v_relative_timings.png', dpi=300)