diff --git a/generate_reports.py b/generate_reports.py index 6792a9f..2162a19 100644 --- a/generate_reports.py +++ b/generate_reports.py @@ -61,7 +61,9 @@ for decimals in [1, 2, 5, 10, 100, 1000, 2000]: f.write(f"| {rank} | {lang} | {time_ms} | {memory} | {instructions} | {cycles} | {ipc:.2f} | {lang_type} |\n") # Footer - f.write(f"\n## Detailed Results\n\n") + f.write(f"\n## Visualizations\n\n") + f.write(f"![Performance Comparison](100_decimals.png)\n\n") + f.write(f"## Detailed Results\n\n") f.write(f"See the full test output in `reports/run_{decimals}_output.txt`.\n\n") f.write("---\n") f.write("*Generated from Pi Calculation Benchmark - Apple A18 Pro Performance Study*\n") diff --git a/generate_visualizations.py b/generate_visualizations.py new file mode 100644 index 0000000..4d6a1e8 --- /dev/null +++ b/generate_visualizations.py @@ -0,0 +1,135 @@ +#!/usr/bin/env python3 +import os +import csv +import json +import matplotlib.pyplot as plt +import matplotlib +matplotlib.use('Agg') # Non-interactive backend +import numpy as np + +# Read analysis data +with open('data/analysis.json', 'r') as f: + data = json.load(f) + +# Define language types +compiled = ['Assembly', 'C', 'C++', 'Rust', 'Go', 'Nim', 'Odin', 'Fortran', 'Swift', 'Crystal', 'D', 'Zig', 'Objective-C', 'Haskell'] +jit = ['Java', 'CSharp', 'Kotlin', 'Scala', 'Dart', 'Julia'] +interpreted = ['Python', 'JavaScript', 'TypeScript', 'Ruby', 'PHP', 'Perl', 'Lua', 'Bash', 'Brainfuck', 'Elixir', 'Erlang', 'R'] + +def get_type(lang): + if lang in compiled: + return 'Compiled' + elif lang in jit: + return 'JIT' + else: + return 'Interpreted' + +def get_color(lang): + lang_type = get_type(lang) + if lang_type == 'Compiled': + return '#2ecc71' # Green + elif lang_type == 'JIT': + return '#3498db' # Blue + else: + return '#e74c3c' # Red + +# Create visualizations for each decimal level +for decimals in [1, 2, 5, 10, 100, 1000, 2000]: + print(f"Creating visualizations for {decimals} decimals...") + + # Sort by time + sorted_langs = sorted(data.keys(), key=lambda x: data[x].get('time_ms', float('inf'))) + + # Create figure with subplots + fig, axes = plt.subplots(2, 2, figsize=(16, 12)) + fig.suptitle(f'Performance Comparison - {decimals} Decimal{"s" if decimals > 1 else ""}', fontsize=16, fontweight='bold') + + # Plot 1: Time comparison (top 20) + ax1 = axes[0, 0] + top_20 = sorted_langs[:20] + times = [data[lang]['time_ms'] for lang in top_20] + colors = [get_color(lang) for lang in top_20] + + bars1 = ax1.barh(range(len(top_20)), times, color=colors) + ax1.set_yticks(range(len(top_20))) + ax1.set_yticklabels(top_20) + ax1.set_xlabel('Time (ms)') + ax1.set_title('Execution Time (Top 20)') + ax1.invert_yaxis() + + # Add value labels + for i, (bar, time) in enumerate(zip(bars1, times)): + ax1.text(time + 1, i, f'{time:.0f}ms', va='center', fontsize=8) + + # Plot 2: Memory comparison (top 20) + ax2 = axes[0, 1] + sorted_by_memory = sorted(data.keys(), key=lambda x: data[x].get('memory_bytes', float('inf'))) + top_20_mem = sorted_by_memory[:20] + memories = [data[lang]['memory_bytes'] / (1024 * 1024) for lang in top_20_mem] # Convert to MB + colors_mem = [get_color(lang) for lang in top_20_mem] + + bars2 = ax2.barh(range(len(top_20_mem)), memories, color=colors_mem) + ax2.set_yticks(range(len(top_20_mem))) + ax2.set_yticklabels(top_20_mem) + ax2.set_xlabel('Memory (MB)') + ax2.set_title('Memory Usage (Top 20)') + ax2.invert_yaxis() + + # Add value labels + for i, (bar, mem) in enumerate(zip(bars2, memories)): + ax2.text(mem + 0.1, i, f'{mem:.1f}MB', va='center', fontsize=8) + + # Plot 3: IPC comparison (top 20) + ax3 = axes[1, 0] + sorted_by_ipc = sorted(data.keys(), key=lambda x: data[x].get('ipc', 0), reverse=True) + top_20_ipc = sorted_by_ipc[:20] + ipcs = [data[lang]['ipc'] for lang in top_20_ipc] + colors_ipc = [get_color(lang) for lang in top_20_ipc] + + bars3 = ax3.barh(range(len(top_20_ipc)), ipcs, color=colors_ipc) + ax3.set_yticks(range(len(top_20_ipc))) + ax3.set_yticklabels(top_20_ipc) + ax3.set_xlabel('IPC (Instructions Per Cycle)') + ax3.set_title('CPU Efficiency (Top 20)') + ax3.invert_yaxis() + + # Add value labels + for i, (bar, ipc) in enumerate(zip(bars3, ipcs)): + ax3.text(ipc + 0.05, i, f'{ipc:.2f}', va='center', fontsize=8) + + # Plot 4: Time vs Memory scatter plot + ax4 = axes[1, 1] + for lang in data.keys(): + time = data[lang]['time_ms'] + memory = data[lang]['memory_bytes'] / (1024 * 1024) # Convert to MB + color = get_color(lang) + ax4.scatter(time, memory, c=color, s=100, alpha=0.6, edgecolors='black', linewidths=0.5) + + # Add label for top performers + if time < 30 or memory < 2: + ax4.annotate(lang, (time, memory), fontsize=7, ha='center', va='bottom') + + ax4.set_xlabel('Time (ms)') + ax4.set_ylabel('Memory (MB)') + ax4.set_title('Time vs Memory Trade-off') + ax4.grid(True, alpha=0.3) + + # Add legend + from matplotlib.patches import Patch + legend_elements = [ + Patch(facecolor='#2ecc71', label='Compiled'), + Patch(facecolor='#3498db', label='JIT'), + Patch(facecolor='#e74c3c', label='Interpreted') + ] + ax4.legend(handles=legend_elements, loc='upper right') + + plt.tight_layout() + + # Save figure + output_file = f'reports/{decimals}_decimals.png' + plt.savefig(output_file, dpi=150, bbox_inches='tight') + plt.close() + + print(f"✓ Created {output_file}") + +print("\n=== All visualizations created ===") \ No newline at end of file diff --git a/reports/1000_decimals.md b/reports/1000_decimals.md index 9066ba6..792a84f 100644 --- a/reports/1000_decimals.md +++ b/reports/1000_decimals.md @@ -54,6 +54,10 @@ | 31 | Scala | 471 | 55973205 | 18880700 | 8929948 | 2.11 | JIT | | 32 | TypeScript | 1361 | 208289792 | 17642488 | 7699920 | 2.29 | Interpreted | +## Visualizations + +![Performance Comparison](100_decimals.png) + ## Detailed Results See the full test output in `reports/run_1000_output.txt`. diff --git a/reports/1000_decimals.png b/reports/1000_decimals.png new file mode 100644 index 0000000..8ed967d Binary files /dev/null and b/reports/1000_decimals.png differ diff --git a/reports/100_decimals.md b/reports/100_decimals.md index 8b4ecc5..abdd724 100644 --- a/reports/100_decimals.md +++ b/reports/100_decimals.md @@ -54,6 +54,10 @@ | 31 | Scala | 471 | 55973205 | 18880700 | 8929948 | 2.11 | JIT | | 32 | TypeScript | 1361 | 208289792 | 17642488 | 7699920 | 2.29 | Interpreted | +## Visualizations + +![Performance Comparison](100_decimals.png) + ## Detailed Results See the full test output in `reports/run_100_output.txt`. diff --git a/reports/100_decimals.png b/reports/100_decimals.png new file mode 100644 index 0000000..bb436a9 Binary files /dev/null and b/reports/100_decimals.png differ diff --git a/reports/10_decimals.md b/reports/10_decimals.md index 84e9e18..d594ff7 100644 --- a/reports/10_decimals.md +++ b/reports/10_decimals.md @@ -54,6 +54,10 @@ | 31 | Scala | 471 | 55973205 | 18880700 | 8929948 | 2.11 | JIT | | 32 | TypeScript | 1361 | 208289792 | 17642488 | 7699920 | 2.29 | Interpreted | +## Visualizations + +![Performance Comparison](100_decimals.png) + ## Detailed Results See the full test output in `reports/run_10_output.txt`. diff --git a/reports/10_decimals.png b/reports/10_decimals.png new file mode 100644 index 0000000..d4f1d2f Binary files /dev/null and b/reports/10_decimals.png differ diff --git a/reports/1_decimals.md b/reports/1_decimals.md index 47ce654..793b8c6 100644 --- a/reports/1_decimals.md +++ b/reports/1_decimals.md @@ -54,6 +54,10 @@ | 31 | Scala | 471 | 55973205 | 18880700 | 8929948 | 2.11 | JIT | | 32 | TypeScript | 1361 | 208289792 | 17642488 | 7699920 | 2.29 | Interpreted | +## Visualizations + +![Performance Comparison](100_decimals.png) + ## Detailed Results See the full test output in `reports/run_1_output.txt`. diff --git a/reports/1_decimals.png b/reports/1_decimals.png new file mode 100644 index 0000000..c888263 Binary files /dev/null and b/reports/1_decimals.png differ diff --git a/reports/2000_decimals.md b/reports/2000_decimals.md index 0b1192d..1a4397b 100644 --- a/reports/2000_decimals.md +++ b/reports/2000_decimals.md @@ -54,6 +54,10 @@ | 31 | Scala | 471 | 55973205 | 18880700 | 8929948 | 2.11 | JIT | | 32 | TypeScript | 1361 | 208289792 | 17642488 | 7699920 | 2.29 | Interpreted | +## Visualizations + +![Performance Comparison](100_decimals.png) + ## Detailed Results See the full test output in `reports/run_2000_output.txt`. diff --git a/reports/2000_decimals.png b/reports/2000_decimals.png new file mode 100644 index 0000000..c074357 Binary files /dev/null and b/reports/2000_decimals.png differ diff --git a/reports/2_decimals.md b/reports/2_decimals.md index 84a186d..45e0737 100644 --- a/reports/2_decimals.md +++ b/reports/2_decimals.md @@ -54,6 +54,10 @@ | 31 | Scala | 471 | 55973205 | 18880700 | 8929948 | 2.11 | JIT | | 32 | TypeScript | 1361 | 208289792 | 17642488 | 7699920 | 2.29 | Interpreted | +## Visualizations + +![Performance Comparison](100_decimals.png) + ## Detailed Results See the full test output in `reports/run_2_output.txt`. diff --git a/reports/2_decimals.png b/reports/2_decimals.png new file mode 100644 index 0000000..7426b70 Binary files /dev/null and b/reports/2_decimals.png differ diff --git a/reports/5_decimals.md b/reports/5_decimals.md index 1895956..aa4697f 100644 --- a/reports/5_decimals.md +++ b/reports/5_decimals.md @@ -54,6 +54,10 @@ | 31 | Scala | 471 | 55973205 | 18880700 | 8929948 | 2.11 | JIT | | 32 | TypeScript | 1361 | 208289792 | 17642488 | 7699920 | 2.29 | Interpreted | +## Visualizations + +![Performance Comparison](100_decimals.png) + ## Detailed Results See the full test output in `reports/run_5_output.txt`. diff --git a/reports/5_decimals.png b/reports/5_decimals.png new file mode 100644 index 0000000..81d3ebd Binary files /dev/null and b/reports/5_decimals.png differ