#!/usr/bin/env python3 """Create separate report files for each decimal level.""" import re from pathlib import Path # Read README with open('README.md', 'r') as f: content = f.read() # Decimal levels to extract decimal_levels = [1, 2, 5, 10, 100, 1000, 2000] # Create reports directory Path('reports').mkdir(exist_ok=True) # Extract sections for each decimal level for level in decimal_levels: # Find the section for this decimal level pattern = rf'#### {level} Decimal[s]?\n\n(.*?)(?=#### \d+ Decimal|### |$)' match = re.search(pattern, content, re.DOTALL) if match: section = match.group(1) # Create report file report_content = f"""# Performance Report: {level} Decimal{'s' if level > 1 else ''} ## Test Environment **Hardware:** - **Model:** MacBook Neo (Mac17,5) - **Processor:** Apple A18 Pro (6 cores: 2 performance + 4 efficiency) - **Memory:** 8 GB RAM - **Operating System:** macOS (Darwin) ## Performance Charts {section} --- *Generated from Pi Calculation Benchmark - {level} decimal{'s' if level > 1 else ''} precision* """ # Write report file filename = f'reports/{level}_decimals.md' with open(filename, 'w') as f: f.write(report_content) print(f"Created {filename}") else: print(f"No section found for {level} decimals") # Create main summary report summary_content = """# Pi Calculation Benchmark: Performance Summary ## Overview This study compares the performance of 34 programming languages when calculating π (pi) with high precision. ## Test Environment **Hardware:** - **Model:** MacBook Neo (Mac17,5) - **Processor:** Apple A18 Pro (6 cores: 2 performance + 4 efficiency) - **Memory:** 8 GB RAM - **Operating System:** macOS (Darwin) ## Method: Machin's Formula All implementations use Machin's formula for π calculation: ``` π/4 = 4·arctan(1/5) - arctan(1/239) ``` ## Performance Reports by Decimal Level - [1 Decimal](reports/1_decimals.md) - Minimal precision - [2 Decimals](reports/2_decimals.md) - Low precision - [5 Decimals](reports/5_decimals.md) - Medium precision - [10 Decimals](reports/10_decimals.md) - Standard precision - [100 Decimals](reports/100_decimals.md) - High precision - [1000 Decimals](reports/1000_decimals.md) - Very high precision - [2000 Decimals](reports/2000_decimals.md) - Extreme precision ## Key Findings ### Fastest Languages (100 decimals) 1. **C** - 9ms (compiled) 2. **Assembly** - 9ms (compiled) 3. **Rust** - 9ms (compiled) 4. **Go** - 9ms (compiled) 5. **Nim** - 9ms (compiled) ### Memory Efficiency (100 decimals) - **C, Rust, Assembly**: < 1 MB - **JIT Languages**: ~2 MB - **Interpreted Languages**: ~2 MB ### Performance Scaling - Compiled languages maintain consistent performance across all decimal levels - JIT languages show startup overhead but good performance - Interpreted languages scale poorly with increased precision --- *Generated from Pi Calculation Benchmark* """ with open('reports/summary.md', 'w') as f: f.write(summary_content) print("Created reports/summary.md") print("\nAll reports created successfully!")