|
| 1 | +import numpy as np |
| 2 | +import matplotlib.pyplot as plt |
| 3 | + |
| 4 | + |
| 5 | +def load_performance_data(): |
| 6 | + threads = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] |
| 7 | + elapsed_time = [4547588, 4580443, 3142521, 2290600, 2028613, 2349594, 2276177, 2192905, 1946464, 1484296, 1914334, |
| 8 | + 1735396, 2040608, 1672974, 1699116, 1654355, 1756129, 1337214, 1685929, 1849847, 1995665] |
| 9 | + return np.array(threads), np.array(elapsed_time) |
| 10 | + |
| 11 | + |
| 12 | +def plot_performance(threads, elapsed_time): |
| 13 | + plt.figure(figsize=(10, 6)) |
| 14 | + plt.plot(threads, elapsed_time, 'bo-') |
| 15 | + plt.xlabel('Number of Threads') |
| 16 | + plt.ylabel('Elapsed Time per Step (ns)') |
| 17 | + plt.title('Performance Analysis: Thread Count vs Elapsed Time') |
| 18 | + plt.grid(True) |
| 19 | + |
| 20 | + # Calculate and annotate speedup |
| 21 | + baseline_time = elapsed_time[0] |
| 22 | + speedup = baseline_time / elapsed_time |
| 23 | + |
| 24 | + # Add text box with statistics |
| 25 | + stats_text = f'Max Speedup: {speedup.max():.2f}x\n' |
| 26 | + stats_text += f'Optimal Thread Count: {threads[speedup.argmax()]}' |
| 27 | + plt.text(0.02, 0.98, stats_text, transform=plt.gca().transAxes, |
| 28 | + verticalalignment='top', bbox=dict(boxstyle='round', facecolor='white', alpha=0.8)) |
| 29 | + |
| 30 | + plt.tight_layout() |
| 31 | + plt.show() |
| 32 | + |
| 33 | + |
| 34 | +if __name__ == "__main__": |
| 35 | + threads, times = load_performance_data() |
| 36 | + plot_performance(threads, times) |
0 commit comments