From 43870e59206b799ef23aeb448c7a58924bdb9a7a Mon Sep 17 00:00:00 2001 From: Ein Anderssono Date: Thu, 23 Apr 2026 10:16:20 +0200 Subject: [PATCH] Reorganize documentation: create separate reports for each decimal level - Create reports/ directory with detailed performance reports - Simplify README.md to provide overview and summary - Add links to detailed reports for each decimal level (1, 2, 5, 10, 100, 1000, 2000) - Keep summary table and key findings in main README - Remove verbose charts from main README to reduce noise --- README.md | 885 ++++---------------------------------- README_old.md | 886 +++++++++++++++++++++++++++++++++++++++ create_reports.py | 116 +++++ reports/1000_decimals.md | 44 ++ reports/100_decimals.md | 52 +++ reports/10_decimals.md | 44 ++ reports/1_decimals.md | 44 ++ reports/2000_decimals.md | 44 ++ reports/2_decimals.md | 44 ++ reports/5_decimals.md | 44 ++ reports/summary.md | 54 +++ update_memory_bytes.py | 143 +++++++ update_memory_charts.py | 84 ++++ 13 files changed, 1673 insertions(+), 811 deletions(-) create mode 100644 README_old.md create mode 100644 create_reports.py create mode 100644 reports/1000_decimals.md create mode 100644 reports/100_decimals.md create mode 100644 reports/10_decimals.md create mode 100644 reports/1_decimals.md create mode 100644 reports/2000_decimals.md create mode 100644 reports/2_decimals.md create mode 100644 reports/5_decimals.md create mode 100644 reports/summary.md create mode 100644 update_memory_bytes.py create mode 100644 update_memory_charts.py diff --git a/README.md b/README.md index 74816e3..48517d3 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ## Overview -This study compares the performance of 34 programming languages when calculating π (pi) with high precision. The benchmark uses Machin's formula and measures execution time for 100, 1000, and 10000 decimal places. +This study compares the performance of 34 programming languages when calculating π (pi) with high precision. The benchmark uses Machin's formula and measures execution time across multiple decimal precision levels. ## Test Environment @@ -19,6 +19,7 @@ This study compares the performance of 34 programming languages when calculating - First run is considered "warmup" and excluded - Results are the average of the 3 subsequent runs - Time measured in milliseconds (ms) +- Memory measured in bytes via RSS (Resident Set Size) ## Method: Machin's Formula @@ -40,847 +41,109 @@ arctan(x) = x - x³/3 + x⁵/5 - x⁷/7 + ... 3. High precision possible 4. Only integer arithmetic required -## Results +## Performance Reports -### Performance Charts by Language (100 decimals) +Detailed performance reports are available for each decimal precision level: -The following Mermaid charts show performance for each language with actual test data: +- **[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 -#### Compiled Languages (Native Code) - Fastest +## Summary Results (100 Decimals) -```mermaid -xychart-beta - title "Compiled Languages - Time (ms) at 100 decimals" - x-axis ["Assembly", "C", "C++", "Rust", "Go", "Nim", "Odin", "Fortran", "Swift", "Crystal"] - y-axis "Time (ms)" 0 --> 35 - bar [9, 9, 9, 9, 9, 9, 9, 27, 29, 28] -``` +### Fastest Languages -```mermaid -xychart-beta - title "Compiled Languages - Memory Usage (bytes) at 100 decimals" - x-axis ["Assembly", "C", "C++", "Rust", "Go", "Nim", "Odin", "Fortran", "Swift", "Crystal"] - y-axis "Memory (bytes)" 0 --> 1000000 - bar [966656, 180224, 196608, 0, 180224, 0, 0, 196608, 262144, 180224] -``` +| Rank | Language | Time (ms) | Memory (bytes) | Type | +|------|-----------|-----------|----------------|------| +| 1 | C | 9 | 180,224 | Compiled | +| 2 | Assembly | 9 | 966,656 | Compiled | +| 3 | Rust | 9 | 0 | Compiled | +| 4 | Go | 9 | 180,224 | Compiled | +| 5 | Nim | 9 | 0 | Compiled | +| 6 | C++ | 9 | 196,608 | Compiled | +| 7 | Odin | 9 | 0 | Compiled | +| 8 | Fortran | 27 | 196,608 | Compiled | +| 9 | Swift | 29 | 262,144 | Compiled | +| 10 | Crystal | 28 | 180,224 | Compiled | -#### JIT-Compiled Languages +### Language Categories -```mermaid -xychart-beta - title "JIT-Compiled Languages - Time (ms) at 100 decimals" - x-axis ["Java", "C#", "Kotlin", "Julia"] - y-axis "Time (ms)" 0 --> 300 - bar [57, 57, 83, 290] -``` - -```mermaid -xychart-beta - title "JIT-Compiled Languages - Memory Usage (bytes) at 100 decimals" - x-axis ["Java", "C#", "Kotlin", "Julia"] - y-axis "Memory (bytes)" 0 --> 2100000 - bar [2064384, 2080768, 2048000, 2080768] -``` - -#### Interpreted Languages - -```mermaid -xychart-beta - title "Interpreted Languages - Time (ms) at 100 decimals" - x-axis ["Python", "Perl", "PHP", "Ruby", "JavaScript"] - y-axis "Time (ms)" 0 --> 90 - bar [57, 55, 77, 79, 84] -``` - -```mermaid -xychart-beta - title "Interpreted Languages - Memory Usage (bytes) at 100 decimals" - x-axis ["Python", "Perl", "PHP", "Ruby", "JavaScript"] - y-axis "Memory (bytes)" 0 --> 2100000 - bar [2048000, 2048000, 2080768, 2064384, 2080768] -``` - -#### Slowest Languages - -```mermaid -xychart-beta - title "Slowest Languages - Time (ms) at 100 decimals" - x-axis ["Erlang", "R", "Elixir", "Scala", "TypeScript"] - y-axis "Time (ms)" 0 --> 900 - bar [130, 349, 898, 58, 154] -``` - -### Performance Scaling by Decimal Count - -#### 1 Decimal - -**Compiled Languages:** -```mermaid -xychart-beta - title "Compiled Languages - Time (ms) at 1 decimal" - x-axis ["Assembly", "C", "C++", "Rust", "Go", "Nim", "Odin", "Fortran", "Swift", "Crystal"] - y-axis "Time (ms)" 0 --> 35 - bar [10, 10, 9, 9, 9, 9, 9, 28, 29, 28] -``` +**Compiled Languages (Native Code):** +- Fastest execution (9-29 ms) +- Minimal memory usage (0-966,656 bytes) +- Consistent performance across decimal levels **JIT-Compiled Languages:** -```mermaid -xychart-beta - title "JIT-Compiled Languages - Time (ms) at 1 decimal" - x-axis ["Java", "C#", "Kotlin", "Julia"] - y-axis "Time (ms)" 0 --> 300 - bar [57, 58, 83, 297] -``` - -**Interpreted Languages:** -```mermaid -xychart-beta - title "Interpreted Languages - Time (ms) at 1 decimal" - x-axis ["Python", "Perl", "PHP", "Ruby", "JavaScript"] - y-axis "Time (ms)" 0 --> 90 - bar [57, 54, 78, 79, 82] -``` - -#### 2 Decimals - -**Compiled Languages:** -```mermaid -xychart-beta - title "Compiled Languages - Time (ms) at 2 decimals" - x-axis ["Assembly", "C", "C++", "Rust", "Go", "Nim", "Odin", "Fortran", "Swift", "Crystal"] - y-axis "Time (ms)" 0 --> 35 - bar [9, 9, 9, 9, 9, 9, 9, 26, 29, 28] -``` - -**JIT-Compiled Languages:** -```mermaid -xychart-beta - title "JIT-Compiled Languages - Time (ms) at 2 decimals" - x-axis ["Java", "C#", "Kotlin", "Julia"] - y-axis "Time (ms)" 0 --> 300 - bar [57, 57, 83, 294] -``` - -**Interpreted Languages:** -```mermaid -xychart-beta - title "Interpreted Languages - Time (ms) at 2 decimals" - x-axis ["Python", "Perl", "PHP", "Ruby", "JavaScript"] - y-axis "Time (ms)" 0 --> 90 - bar [57, 53, 79, 80, 83] -``` - -#### 5 Decimals - -**Compiled Languages:** -```mermaid -xychart-beta - title "Compiled Languages - Time (ms) at 5 decimals" - x-axis ["Assembly", "C", "C++", "Rust", "Go", "Nim", "Odin", "Fortran", "Swift", "Crystal"] - y-axis "Time (ms)" 0 --> 35 - bar [8, 10, 9, 9, 9, 9, 9, 15, 28, 28] -``` - -**JIT-Compiled Languages:** -```mermaid -xychart-beta - title "JIT-Compiled Languages - Time (ms) at 5 decimals" - x-axis ["Java", "C#", "Kotlin", "Julia"] - y-axis "Time (ms)" 0 --> 300 - bar [57, 57, 83, 292] -``` - -**Interpreted Languages:** -```mermaid -xychart-beta - title "Interpreted Languages - Time (ms) at 5 decimals" - x-axis ["Python", "Perl", "PHP", "Ruby", "JavaScript"] - y-axis "Time (ms)" 0 --> 90 - bar [57, 55, 80, 80, 83] -``` - -#### 10 Decimals - -**Compiled Languages:** -```mermaid -xychart-beta - title "Compiled Languages - Time (ms) at 10 decimals" - x-axis ["Assembly", "C", "C++", "Rust", "Go", "Nim", "Odin", "Fortran", "Swift", "Crystal"] - y-axis "Time (ms)" 0 --> 40 - bar [9, 9, 9, 9, 9, 9, 9, 21, 29, 29] -``` - -**JIT-Compiled Languages:** -```mermaid -xychart-beta - title "JIT-Compiled Languages - Time (ms) at 10 decimals" - x-axis ["Java", "C#", "Kotlin", "Julia"] - y-axis "Time (ms)" 0 --> 310 - bar [58, 58, 83, 302] -``` - -**Interpreted Languages:** -```mermaid -xychart-beta - title "Interpreted Languages - Time (ms) at 10 decimals" - x-axis ["Python", "Perl", "PHP", "Ruby", "JavaScript"] - y-axis "Time (ms)" 0 --> 90 - bar [57, 54, 78, 79, 83] -``` - -#### 1000 Decimals - -**Compiled Languages:** -```mermaid -xychart-beta - title "Compiled Languages - Time (ms) at 1000 decimals" - x-axis ["Assembly", "C", "C++", "Rust", "Go", "Nim", "Odin", "Fortran", "Swift", "Crystal"] - y-axis "Time (ms)" 0 --> 35 - bar [9, 9, 30, 9, 9, 9, 9, 31, 29, 29] -``` - -**JIT-Compiled Languages:** -```mermaid -xychart-beta - title "JIT-Compiled Languages - Time (ms) at 1000 decimals" - x-axis ["Java", "C#", "Kotlin", "Julia"] - y-axis "Time (ms)" 0 --> 310 - bar [57, 57, 83, 299] -``` - -**Interpreted Languages:** -```mermaid -xychart-beta - title "Interpreted Languages - Time (ms) at 1000 decimals" - x-axis ["Python", "Perl", "PHP", "Ruby", "JavaScript"] - y-axis "Time (ms)" 0 --> 240 - bar [60, 103, 79, 79, 233] -``` - -#### 2000 Decimals - -**Compiled Languages:** -```mermaid -xychart-beta - title "Compiled Languages - Time (ms) at 2000 decimals" - x-axis ["Assembly", "C", "C++", "Rust", "Go", "Nim", "Odin", "Fortran", "Swift", "Crystal"] - y-axis "Time (ms)" 0 --> 35 - bar [9, 27, 33, 9, 9, 9, 9, 31, 29, 29] -``` - -**JIT-Compiled Languages:** -```mermaid -xychart-beta - title "JIT-Compiled Languages - Time (ms) at 2000 decimals" - x-axis ["Java", "C#", "Kotlin", "Julia"] - y-axis "Time (ms)" 0 --> 310 - bar [57, 57, 83, 299] -``` - -**Interpreted Languages:** -```mermaid -xychart-beta - title "Interpreted Languages - Time (ms) at 2000 decimals" - x-axis ["Python", "Perl", "PHP", "Ruby", "JavaScript"] - y-axis "Time (ms)" 0 --> 240 - bar [60, 103, 79, 79, 233] -``` - -### Resource Usage Over Time - -The following charts show memory usage throughout the program's entire lifetime. The X-axis shows time in milliseconds from start to finish, and the Y-axis shows memory usage in MB. Each chart is scaled to clearly show variations for that specific language. - -#### Compiled Languages (Native Code) - -##### C - Fastest Language (11ms, minimal memory) - -```mermaid -xychart-beta - title "C - Memory Usage Over Time" - x-axis "Time (ms)" 0 --> 12 - y-axis "Memory (MB)" 0 --> 1 - line [0.2, 0.2, 0.2, 0.2, 0.0] -``` - -**Analysis:** C uses practically no memory and executes in 11ms. Memory remains stable at 0 MB throughout execution. - -##### Rust - Fast and Memory-Efficient (11ms) - -```mermaid -xychart-beta - title "Rust - Memory Usage Over Time" - x-axis "Time (ms)" 0 --> 12 - y-axis "Memory (MB)" 0 --> 1 - line [0.0] -``` - -**Analysis:** Rust matches C in performance and memory usage. Zero-cost abstractions provide optimal performance. - -##### Assembly - Low-Level Performance (18ms) - -```mermaid -xychart-beta - title "Assembly - Memory Usage Over Time" - x-axis "Time (ms)" 0 --> 20 - y-axis "Memory (MB)" 0 --> 1 - line [0.9] -``` - -**Analysis:** Assembly shows similar performance to C and Rust with minimal memory. - -##### Haskell - Fast but High Memory (49ms, 10.5MB) - -```mermaid -xychart-beta - title "Haskell - Memory Usage Over Time" - x-axis "Time (ms)" 0 --> 8 - y-axis "Memory (MB)" 0 --> 12 - line [0.2, 9.7, 0.0] -``` - -**Analysis:** Haskell is fast (49ms) but uses significantly more memory (10.5 MB) due to runtime and garbage collector. - -##### Dart - High Memory but Fast (41ms, 9.1MB) - -```mermaid -xychart-beta - title "Dart - Memory Usage Over Time" - x-axis "Time (ms)" 0 --> 12 - y-axis "Memory (MB)" 0 --> 11 - line [0.2, 7.9, 10.8, 10.8, 10.8, 10.8, 10.8, 0.0] -``` - -**Analysis:** Dart shows higher memory usage (9.1 MB) but maintains good performance thanks to JIT compilation. - -#### Interpreted Languages - -##### Elixir - Slow but Stable Memory (338ms, 2MB) - -```mermaid -xychart-beta - title "Elixir - Memory Usage Over Time" - x-axis "Time (ms)" 0 --> 300 - y-axis "Memory (MB)" 0 --> 3 - line [0.5, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0] -``` - -**Analysis:** Elixir is slower (338ms) but shows very stable memory usage at 2 MB throughout execution. The BEAM VM provides predictable memory usage. - -##### TypeScript - Slowest with Varying Memory (1780ms, 2MB) - -```mermaid -xychart-beta - title "TypeScript - Memory Usage Over Time" - x-axis "Time (ms)" 0 --> 1500 - y-axis "Memory (MB)" 0 --> 3 - line [2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0] -``` - -**Analysis:** TypeScript is slowest (1780ms) but shows an interesting memory profile: starts lower (1.9 MB) and quickly stabilizes at 2 MB. - -##### Scala - JVM-Based (737ms, 2MB) - -```mermaid -xychart-beta - title "Scala - Memory Usage Over Time" - x-axis "Time (ms)" 0 --> 360 - y-axis "Memory (MB)" 0 --> 3 - line [2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0] -``` - -**Analysis:** Scala on JVM shows stable memory usage but slower execution due to JVM startup time. - -##### JavaScript - Node.js Performance (169ms, 2MB) - -```mermaid -xychart-beta - title "JavaScript - Memory Usage Over Time" - x-axis "Time (ms)" 0 --> 500 - y-axis "Memory (MB)" 0 --> 3 - line [2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0] -``` - -**Analysis:** JavaScript shows stable memory usage but with an interesting drop at the end (0 MB) when the process terminates. - -#### Memory Usage Comparison - -##### Fast Languages (< 50ms) - Memory Profile - -```mermaid -xychart-beta - title "Fast Languages - Memory Usage Comparison" - x-axis ["C", "Rust", "Assembly", "Go", "Nim", "Odin", "C++", "Fortran", "Swift", "Haskell", "Dart"] - y-axis "Memory (MB)" 0 --> 12 - bar [0, 0, 0, 0, 0, 0, 0, 1, 0, 10.5, 9.1] -``` - -**Analysis:** Most fast languages use minimal memory (0-1 MB), but Haskell and Dart stand out with 9-11 MB due to their runtime environments. - -##### Slow Languages (> 200ms) - Memory Profile - -```mermaid -xychart-beta - title "Slow Languages - Memory Usage Comparison" - x-axis ["Elixir", "Erlang", "R", "Scala", "TypeScript"] - y-axis "Memory (MB)" 0 --> 3 - bar [2.0, 2.0, 2.0, 2.0, 2.0] -``` - -**Analysis:** All slow languages show similar memory usage (2 MB), suggesting that execution time doesn't directly correlate with memory usage. - -### Binary Sizes - -File sizes for compiled binaries (where applicable): - -| Language | Binary Size | Type | -|----------|-------------|------| -| C | 34K | Native binary | -| Assembly | 49K | Native binary | -| Fortran | 34K | Native binary | -| Objective-C | 50K | Native binary | -| Swift | 76K | Native binary | -| Nim | 149K | Native binary | -| Rust | 497K | Native binary | -| Odin | 422K | Native binary | -| C++ | 221K | Native binary | -| Zig | 2.0M | Native binary | -| Crystal | 1.5M | Native binary | -| D | 1.3M | Native binary | -| Go | 2.5M | Native binary | -| Dart | 5.4M | Native binary | -| Haskell | 13M | Native binary | -| C# | 122K | .NET assembly | -| Java | 104B | Wrapper script | -| JavaScript | 103B | Wrapper script | -| Python | 106B | Wrapper script | -| Ruby | 103B | Wrapper script | -| Elixir | 106B | Wrapper script | -| Erlang | 143B | Wrapper script | -| Scala | 114B | Wrapper script | -| Kotlin | 109B | Wrapper script | -| Julia | 104B | Wrapper script | -| TypeScript | 110B | Wrapper script | -| Lua | 103B | Wrapper script | -| Perl | 103B | Wrapper script | -| PHP | 103B | Wrapper script | -| R | 105B | Wrapper script | -| Bash | 103B | Wrapper script | -| Brainfuck | 106B | Wrapper script | -| Vimscript | 467B | Wrapper script | -| Wolfram | 118B | Wrapper script | - -**Note:** Wrapper scripts are small shell scripts that invoke the interpreter. Compiled languages have actual binaries with embedded code. - -### Performance Scaling by Decimal Count - -The following tables show how performance scales with increasing decimal precision: - -#### 1 Decimal - -| Language | Time (ms) | Memory (MB) | Status | -|----------|-----------|-------------|--------| -| Assembly | 10 | 0 | ✓ | -| C | 10 | 0 | ✓ | -| C++ | 9 | 0 | ✓ | -| Rust | 9 | 0 | ✓ | -| Go | 9 | 0 | ✓ | -| Nim | 9 | 0 | ✓ | -| Odin | 9 | 0 | ✓ | -| Swift | 29 | 0 | ✓ | -| Fortran | 28 | 0 | ✓ | -| Objective-C | 32 | 597 | ✓ | -| D | 35 | 9488 | ✓ | -| Crystal | 28 | 0 | ✓ | -| Zig | 32 | 2752 | ✓ | -| Haskell | 17 | 0 | ✓ | -| Lua | 29 | 0 | ✓ | -| Python | 57 | 2000 | ✓ | -| Java | 57 | 2000 | ✓ | -| C# | 58 | 2021 | ✓ | -| JavaScript | 82 | 2037 | ✓ | -| TypeScript | 157 | 2032 | ✓ | -| Perl | 54 | 2005 | ✓ | -| PHP | 78 | 2032 | ✓ | -| Ruby | 79 | 2000 | ✓ | -| Julia | 297 | 2037 | ✓ | -| Elixir | 912 | 2032 | ✓ | -| Erlang | 129 | 2032 | ✓ | -| R | 357 | 2037 | ✓ | -| Scala | 90 | 2000 | ✓ | -| Kotlin | 83 | 2032 | ✓ | -| Dart | 32 | 11600 | ✓ | -| Bash | 36 | 2005 | ✓ | -| Brainfuck | 53 | 2000 | ✓ | - -#### 2 Decimals - -| Language | Time (ms) | Memory (MB) | Status | -|----------|-----------|-------------|--------| -| Assembly | 9 | 0 | ✓ | -| C | 9 | 0 | ✓ | -| C++ | 9 | 0 | ✓ | -| Rust | 9 | 0 | ✓ | -| Go | 9 | 0 | ✓ | -| Nim | 9 | 0 | ✓ | -| Odin | 9 | 0 | ✓ | -| Swift | 29 | 0 | ✓ | -| Fortran | 26 | 0 | ✓ | -| Objective-C | 32 | 496 | ✓ | -| D | 35 | 10032 | ✓ | -| Crystal | 28 | 0 | ✓ | -| Zig | 32 | 2757 | ✓ | -| Haskell | 9 | 0 | ✓ | -| Lua | 30 | 0 | ✓ | -| Python | 57 | 2000 | ✓ | -| Java | 57 | 2000 | ✓ | -| C# | 57 | 2016 | ✓ | -| JavaScript | 83 | 2032 | ✓ | -| TypeScript | 157 | 2032 | ✓ | -| Perl | 53 | 2000 | ✓ | -| PHP | 79 | 2032 | ✓ | -| Ruby | 80 | 2005 | ✓ | -| Julia | 294 | 2032 | ✓ | -| Elixir | 871 | 2037 | ✓ | -| Erlang | 127 | 2032 | ✓ | -| R | 342 | 2032 | ✓ | -| Scala | 58 | 2000 | ✓ | -| Kotlin | 83 | 2032 | ✓ | -| Dart | 31 | 11600 | ✓ | -| Bash | 33 | 2000 | ✓ | -| Brainfuck | 53 | 2005 | ✓ | - -#### 5 Decimals - -| Language | Time (ms) | Memory (MB) | Status | -|----------|-----------|-------------|--------| -| Assembly | 8 | 0 | ✓ | -| C | 10 | 0 | ✓ | -| C++ | 9 | 0 | ✓ | -| Rust | 9 | 0 | ✓ | -| Go | 9 | 0 | ✓ | -| Nim | 9 | 0 | ✓ | -| Odin | 9 | 0 | ✓ | -| Swift | 28 | 0 | ✓ | -| Fortran | 15 | 0 | ✓ | -| Objective-C | 31 | 533 | ✓ | -| D | 35 | 9578 | ✓ | -| Crystal | 28 | 0 | ✓ | -| Zig | 32 | 2757 | ✓ | -| Haskell | 10 | 0 | ✓ | -| Lua | 28 | 0 | ✓ | -| Python | 57 | 2000 | ✓ | -| Java | 57 | 2000 | ✓ | -| C# | 57 | 2016 | ✓ | -| JavaScript | 83 | 2032 | ✓ | -| TypeScript | 156 | 2032 | ✓ | -| Perl | 55 | 2000 | ✓ | -| PHP | 80 | 2032 | ✓ | -| Ruby | 80 | 2000 | ✓ | -| Julia | 292 | 2032 | ✓ | -| Elixir | 881 | 2032 | ✓ | -| Erlang | 129 | 2032 | ✓ | -| R | 374 | 2037 | ✓ | -| Scala | 59 | 2000 | ✓ | -| Kotlin | 83 | 2032 | ✓ | -| Dart | 31 | 11600 | ✓ | -| Bash | 33 | 2000 | ✓ | -| Brainfuck | 53 | 2000 | ✓ | - -#### 10 Decimals - -| Language | Time (ms) | Memory (MB) | Status | -|----------|-----------|-------------|--------| -| Assembly | 9 | 0 | ✓ | -| C | 9 | 0 | ✓ | -| C++ | 9 | 0 | ✓ | -| Rust | 9 | 0 | ✓ | -| Go | 9 | 0 | ✓ | -| Nim | 9 | 0 | ✓ | -| Odin | 9 | 0 | ✓ | -| Swift | 29 | 0 | ✓ | -| Fortran | 21 | 0 | ✓ | -| Objective-C | 32 | 1066 | ✓ | -| D | 36 | 9669 | ✓ | -| Crystal | 29 | 0 | ✓ | -| Zig | 33 | 2773 | ✓ | -| Haskell | 9 | 0 | ✓ | -| Lua | 30 | 0 | ✓ | -| Python | 57 | 2000 | ✓ | -| Java | 58 | 2000 | ✓ | -| C# | 58 | 2000 | ✓ | -| JavaScript | 83 | 2037 | ✓ | -| TypeScript | 155 | 2032 | ✓ | -| Perl | 54 | 2000 | ✓ | -| PHP | 78 | 2032 | ✓ | -| Ruby | 79 | 2000 | ✓ | -| Julia | 302 | 2032 | ✓ | -| Elixir | 910 | 2032 | ✓ | -| Erlang | 130 | 2042 | ✓ | -| R | 336 | 2037 | ✓ | -| Scala | 58 | 2000 | ✓ | -| Kotlin | 83 | 2032 | ✓ | -| Dart | 32 | 11696 | ✓ | -| Bash | 34 | 2000 | ✓ | -| Brainfuck | 52 | 2000 | ✓ | - -#### 100 Decimals - -| Language | Time (ms) | Memory (MB) | Status | -|----------|-----------|-------------|--------| -| Assembly | 9 | 0 | ✓ | -| C | 9 | 0 | ✓ | -| C++ | 9 | 0 | ✓ | -| Rust | 9 | 0 | ✓ | -| Go | 9 | 0 | ✓ | -| Nim | 9 | 0 | ✓ | -| Odin | 9 | 0 | ✓ | -| Swift | 29 | 0 | ✓ | -| Fortran | 27 | 0 | ✓ | -| Objective-C | 31 | 752 | ✓ | -| D | 35 | 10154 | ✓ | -| Crystal | 28 | 0 | ✓ | -| Zig | 33 | 2730 | ✓ | -| Haskell | 9 | 0 | ✓ | -| Lua | 29 | 0 | ✓ | -| Python | 57 | 2000 | ✓ | -| Java | 57 | 2000 | ✓ | -| C# | 57 | 2016 | ✓ | -| JavaScript | 84 | 2032 | ✓ | -| TypeScript | 154 | 2032 | ✓ | -| Perl | 55 | 2000 | ✓ | -| PHP | 77 | 2032 | ✓ | -| Ruby | 79 | 2000 | ✓ | -| Julia | 290 | 2032 | ✓ | -| Elixir | 898 | 2037 | ✓ | -| Erlang | 130 | 2037 | ✓ | -| R | 349 | 2032 | ✓ | -| Scala | 58 | 2000 | ✓ | -| Kotlin | 83 | 2032 | ✓ | -| Dart | 31 | 11749 | ✓ | -| Bash | 32 | 2000 | ✓ | -| Brainfuck | 54 | 2005 | ✓ | - -#### 1000 Decimals - -| Language | Time (ms) | Memory (MB) | Status | -|----------|-----------|-------------|--------| -| Assembly | 9 | 0 | ✓ | -| C | 9 | 0 | ✓ | -| C++ | 30 | 0 | ✓ | -| Rust | 9 | 0 | ✓ | -| Go | 9 | 0 | ✓ | -| Nim | 9 | 0 | ✓ | -| Odin | 9 | 0 | ✓ | -| Swift | 29 | 0 | ✓ | -| Fortran | 31 | 1754 | ✓ | -| Objective-C | 32 | 496 | ✓ | -| D | 36 | 9712 | ✓ | -| Crystal | 29 | 0 | ✓ | -| Zig | 33 | 2965 | ✓ | -| Haskell | 23 | 0 | ✓ | -| Lua | 29 | 0 | ✓ | -| Python | 60 | 2000 | ✓ | -| Java | 57 | 2000 | ✓ | -| C# | 57 | 2026 | ✓ | -| JavaScript | 233 | 2032 | ✓ | -| TypeScript | 157 | 2032 | ✓ | -| Perl | 103 | 2005 | ✓ | -| PHP | 79 | 2032 | ✓ | -| Ruby | 79 | 2000 | ✓ | -| Julia | 299 | 2032 | ✓ | -| Elixir | 1086 | 2037 | ✓ | -| Erlang | 138 | 2037 | ✓ | -| R | 337 | 2042 | ✓ | -| Scala | 58 | 2000 | ✓ | -| Kotlin | 83 | 2032 | ✓ | -| Dart | 31 | 11792 | ✓ | -| Bash | 33 | 2000 | ✓ | -| Brainfuck | 56 | 2000 | ✓ | - -#### 2000 Decimals - -| Language | Time (ms) | Memory (MB) | Status | -|----------|-----------|-------------|--------| -| Assembly | 9 | 0 | ✓ | -| C | 27 | 0 | ✓ | -| C++ | 33 | 1472 | ✓ | -| Rust | 9 | 0 | ✓ | -| Go | 9 | 0 | ✓ | -| Nim | 9 | 0 | ✓ | -| Odin | 9 | 0 | ✓ | -| Swift | 29 | 0 | ✓ | -| Fortran | 31 | 1754 | ✓ | -| Objective-C | 32 | 512 | ✓ | -| D | 36 | 9712 | ✓ | -| Crystal | 29 | 0 | ✓ | -| Zig | 33 | 2965 | ✓ | -| Haskell | 23 | 0 | ✓ | -| Lua | 29 | 0 | ✓ | -| Python | 60 | 2000 | ✓ | -| Java | 57 | 2000 | ✓ | -| C# | 57 | 2016 | ✓ | -| JavaScript | 233 | 2032 | ✓ | -| TypeScript | 157 | 2032 | ✓ | -| Perl | 103 | 2005 | ✓ | -| PHP | 79 | 2032 | ✓ | -| Ruby | 79 | 2000 | ✓ | -| Julia | 299 | 2032 | ✓ | -| Elixir | 1086 | 2037 | ✓ | -| Erlang | 138 | 2037 | ✓ | -| R | 337 | 2042 | ✓ | -| Scala | 58 | 2000 | ✓ | -| Kotlin | 83 | 2032 | ✓ | -| Dart | 31 | 11792 | ✓ | -| Bash | 33 | 2000 | ✓ | -| Brainfuck | 56 | 2000 | ✓ | - -### Key Observations - -**Scaling Behavior:** -- **Native compiled languages** (C, Rust, Assembly, Go, Nim, Odin) show minimal performance degradation from 1 to 2000 decimals -- **JIT-compiled languages** (Java, C#, Kotlin) maintain consistent performance across all decimal counts -- **Interpreted languages** (Python, Ruby, JavaScript) show linear scaling with decimal count -- **BEAM languages** (Elixir, Erlang) show significant performance impact at higher decimal counts - -**Memory Efficiency:** -- **Native languages** use minimal memory (0 MB) regardless of decimal count -- **Dart** shows consistently high memory usage (9-12 MB) across all tests -- **Haskell** shows moderate memory usage that scales with complexity -- **Interpreted languages** maintain stable memory usage (~2 MB) across all tests - -**Performance Leaders:** -- **Fastest at all decimal counts:** Assembly, C, C++, Rust, Go, Nim, Odin (all ~9-33ms) -- **Most consistent scaling:** Native compiled languages show near-constant execution time -- **Best memory efficiency:** Native compiled languages with 0 MB memory usage - -## Analysis - -### Performance Categories - -**Native Compiled Languages (30-40ms):** -- Fastest execution due to direct machine code -- Minimal memory footprint (0-1 MB) -- Includes: C, Rust, Go, Assembly, Nim, Odin, C++, Fortran, Swift, Crystal, D, Zig - -**JIT-Compiled Languages (89-299ms):** +- Moderate execution time (57-290 ms) +- Higher memory usage (~2 MB) - Good performance after warmup -- Moderate memory usage (1-2 MB) -- Includes: Java, C#, Kotlin, Julia -**Interpreted Languages (40-1780ms):** -- Slower execution due to interpretation overhead -- Variable memory usage (1-2 MB) -- Includes: Python, Ruby, JavaScript, PHP, Perl, Lua, Bash +**Interpreted Languages:** +- Slower execution (55-84 ms) +- Moderate memory usage (~2 MB) +- Variable performance -**BEAM Languages (311-606ms):** -- Erlang/Elixir on BEAM VM -- Stable memory usage (2 MB) -- Predictable performance +## Key Findings -### Key Findings +1. **Compiled languages dominate**: C, Assembly, Rust, Go, and Nim all execute in ~9ms +2. **Memory efficiency varies**: Compiled languages use minimal memory, JIT/interpreted use ~2 MB +3. **Performance scaling**: Compiled languages maintain consistent performance across all decimal levels +4. **JIT overhead**: Java, C#, Kotlin show startup overhead but good performance +5. **Interpreted languages**: Python, Perl, PHP, Ruby, JavaScript show moderate performance -1. **Memory Efficiency:** Native compiled languages use minimal memory (0-1 MB), while interpreted and JIT languages typically use 2 MB. +## Languages Tested -2. **Performance Scaling:** All languages scale linearly with decimal count. 1000 decimals takes ~10x longer than 100 decimals. +**Compiled (10):** Assembly, C, C++, Rust, Go, Nim, Odin, Fortran, Swift, Crystal -3. **Binary Size vs Performance:** Smaller binaries don't necessarily mean faster execution. Rust (497K) is as fast as C (34K). +**JIT-Compiled (4):** Java, C#, Kotlin, Julia -4. **Runtime Overhead:** Languages with runtime environments (Haskell, Dart) show higher memory usage but maintain good performance. +**Interpreted (5):** Python, Perl, PHP, Ruby, JavaScript -5. **JIT Warmup:** JIT-compiled languages benefit from warmup runs, showing improved performance after initial execution. +**Other (15):** Bash, Brainfuck, D, Dart, Elixir, Erlang, Haskell, Lua, Objective-C, R, Scala, TypeScript, Vimscript, Wolfram, Zig ## Repository Structure ``` . -├── assembly/ # Assembly implementation -├── bash/ # Bash script implementation -├── brainfuck/ # Brainfuck implementation -├── c/ # C implementation -├── cpp/ # C++ implementation -├── crystal/ # Crystal implementation -├── csharp/ # C# implementation -├── d/ # D implementation -├── dart/ # Dart implementation -├── elixir/ # Elixir implementation -├── erlang/ # Erlang implementation -├── fortran/ # Fortran implementation -├── go/ # Go implementation -├── haskell/ # Haskell implementation -├── java/ # Java implementation -├── javascript/ # JavaScript implementation -├── julia/ # Julia implementation -├── kotlin/ # Kotlin implementation -├── objective-c/ # Objective-C implementation -├── scala/ # Scala implementation -├── typescript/ # TypeScript implementation -├── lua/ # Lua implementation -├── nim/ # Nim implementation -├── odin/ # Odin implementation -├── perl/ # Perl implementation -├── php/ # PHP implementation -├── python/ # Python implementation -├── r/ # R implementation -├── ruby/ # Ruby implementation -├── rust/ # Rust implementation -├── swift/ # Swift implementation -├── zig/ # Zig implementation -├── vimscript/ # Vimscript implementation -├── wolfram/ # Wolfram implementation -├── build.sh # Build all implementations -├── run_all.sh # Run all benchmarks -├── test.sh # Test all implementations -├── facit.txt # Expected results -└── README.md # This file +├── README.md # This file +├── reports/ # Detailed performance reports +│ ├── summary.md # Overall summary +│ ├── 1_decimals.md # 1 decimal precision +│ ├── 2_decimals.md # 2 decimals precision +│ ├── 5_decimals.md # 5 decimals precision +│ ├── 10_decimals.md # 10 decimals precision +│ ├── 100_decimals.md # 100 decimals precision +│ ├── 1000_decimals.md # 1000 decimals precision +│ └── 2000_decimals.md # 2000 decimals precision +├── timelines/ # Resource usage timeline data +├── assembly/ # Assembly implementation +├── c/ # C implementation +├── cpp/ # C++ implementation +├── rust/ # Rust implementation +└── ... # Other language implementations ``` -## Building and Running - -### Build All Implementations +## Running the Benchmark ```bash +# Build all languages ./build.sh + +# Run all tests +./run_all.sh + +# Run specific language +cd c && ./build.sh && ./print_hej ``` -This compiles all compiled languages and prepares all implementations. - -### Run Benchmarks - -```bash -./run_all.sh -``` - -Example: -```bash -./run_all.sh 100 # Run with 100 decimals -./run_all.sh 1000 # Run with 1000 decimals -./run_all.sh 10000 # Run with 10000 decimals -``` - -### Test All Implementations - -```bash -./test.sh -``` - -Verifies that all implementations produce correct results. - -## Contributing - -To add a new language: - -1. Create a new directory with the language name -2. Implement `print_hej` that calculates π using Machin's formula -3. Create a `build.sh` script to compile/build -4. Ensure the implementation accepts a command-line argument for decimal count -5. Test with `./test.sh` - ## License -This project is open source and available under the MIT License. +MIT License - See LICENSE file for details. -## Acknowledgments +--- -- Machin's formula for efficient π calculation -- All language maintainers and contributors -- Apple A18 Pro hardware for benchmarking \ No newline at end of file +*Generated from Pi Calculation Benchmark - Apple A18 Pro Performance Study* \ No newline at end of file diff --git a/README_old.md b/README_old.md new file mode 100644 index 0000000..74816e3 --- /dev/null +++ b/README_old.md @@ -0,0 +1,886 @@ +# Pi Calculation Benchmark: Performance Comparison of 34 Programming Languages + +## Overview + +This study compares the performance of 34 programming languages when calculating π (pi) with high precision. The benchmark uses Machin's formula and measures execution time for 100, 1000, and 10000 decimal places. + +## Test Environment + +**Hardware:** +- **Model:** MacBook Neo (Mac17,5) +- **Processor:** Apple A18 Pro + - 6 cores: 2 performance cores + 4 efficiency cores + - Architecture: ARM64 +- **Memory:** 8 GB RAM +- **Operating System:** macOS (Darwin) + +**Methodology:** +- Each language runs 4 times per test +- First run is considered "warmup" and excluded +- Results are the average of the 3 subsequent runs +- Time measured in milliseconds (ms) + +## Method: Machin's Formula + +All implementations use Machin's formula for π calculation: + +``` +π/4 = 4·arctan(1/5) - arctan(1/239) +``` + +Where arctan(x) is calculated using the Taylor series: + +``` +arctan(x) = x - x³/3 + x⁵/5 - x⁷/7 + ... +``` + +**Advantages of this method:** +1. Fast convergence (few terms required) +2. Simple implementation +3. High precision possible +4. Only integer arithmetic required + +## Results + +### Performance Charts by Language (100 decimals) + +The following Mermaid charts show performance for each language with actual test data: + +#### Compiled Languages (Native Code) - Fastest + +```mermaid +xychart-beta + title "Compiled Languages - Time (ms) at 100 decimals" + x-axis ["Assembly", "C", "C++", "Rust", "Go", "Nim", "Odin", "Fortran", "Swift", "Crystal"] + y-axis "Time (ms)" 0 --> 35 + bar [9, 9, 9, 9, 9, 9, 9, 27, 29, 28] +``` + +```mermaid +xychart-beta + title "Compiled Languages - Memory Usage (bytes) at 100 decimals" + x-axis ["Assembly", "C", "C++", "Rust", "Go", "Nim", "Odin", "Fortran", "Swift", "Crystal"] + y-axis "Memory (bytes)" 0 --> 1000000 + bar [966656, 180224, 196608, 0, 180224, 0, 0, 196608, 262144, 180224] +``` + +#### JIT-Compiled Languages + +```mermaid +xychart-beta + title "JIT-Compiled Languages - Time (ms) at 100 decimals" + x-axis ["Java", "C#", "Kotlin", "Julia"] + y-axis "Time (ms)" 0 --> 300 + bar [57, 57, 83, 290] +``` + +```mermaid +xychart-beta + title "JIT-Compiled Languages - Memory Usage (bytes) at 100 decimals" + x-axis ["Java", "C#", "Kotlin", "Julia"] + y-axis "Memory (bytes)" 0 --> 2100000 + bar [2064384, 2080768, 2048000, 2080768] +``` + +#### Interpreted Languages + +```mermaid +xychart-beta + title "Interpreted Languages - Time (ms) at 100 decimals" + x-axis ["Python", "Perl", "PHP", "Ruby", "JavaScript"] + y-axis "Time (ms)" 0 --> 90 + bar [57, 55, 77, 79, 84] +``` + +```mermaid +xychart-beta + title "Interpreted Languages - Memory Usage (bytes) at 100 decimals" + x-axis ["Python", "Perl", "PHP", "Ruby", "JavaScript"] + y-axis "Memory (bytes)" 0 --> 2100000 + bar [2048000, 2048000, 2080768, 2064384, 2080768] +``` + +#### Slowest Languages + +```mermaid +xychart-beta + title "Slowest Languages - Time (ms) at 100 decimals" + x-axis ["Erlang", "R", "Elixir", "Scala", "TypeScript"] + y-axis "Time (ms)" 0 --> 900 + bar [130, 349, 898, 58, 154] +``` + +### Performance Scaling by Decimal Count + +#### 1 Decimal + +**Compiled Languages:** +```mermaid +xychart-beta + title "Compiled Languages - Time (ms) at 1 decimal" + x-axis ["Assembly", "C", "C++", "Rust", "Go", "Nim", "Odin", "Fortran", "Swift", "Crystal"] + y-axis "Time (ms)" 0 --> 35 + bar [10, 10, 9, 9, 9, 9, 9, 28, 29, 28] +``` + +**JIT-Compiled Languages:** +```mermaid +xychart-beta + title "JIT-Compiled Languages - Time (ms) at 1 decimal" + x-axis ["Java", "C#", "Kotlin", "Julia"] + y-axis "Time (ms)" 0 --> 300 + bar [57, 58, 83, 297] +``` + +**Interpreted Languages:** +```mermaid +xychart-beta + title "Interpreted Languages - Time (ms) at 1 decimal" + x-axis ["Python", "Perl", "PHP", "Ruby", "JavaScript"] + y-axis "Time (ms)" 0 --> 90 + bar [57, 54, 78, 79, 82] +``` + +#### 2 Decimals + +**Compiled Languages:** +```mermaid +xychart-beta + title "Compiled Languages - Time (ms) at 2 decimals" + x-axis ["Assembly", "C", "C++", "Rust", "Go", "Nim", "Odin", "Fortran", "Swift", "Crystal"] + y-axis "Time (ms)" 0 --> 35 + bar [9, 9, 9, 9, 9, 9, 9, 26, 29, 28] +``` + +**JIT-Compiled Languages:** +```mermaid +xychart-beta + title "JIT-Compiled Languages - Time (ms) at 2 decimals" + x-axis ["Java", "C#", "Kotlin", "Julia"] + y-axis "Time (ms)" 0 --> 300 + bar [57, 57, 83, 294] +``` + +**Interpreted Languages:** +```mermaid +xychart-beta + title "Interpreted Languages - Time (ms) at 2 decimals" + x-axis ["Python", "Perl", "PHP", "Ruby", "JavaScript"] + y-axis "Time (ms)" 0 --> 90 + bar [57, 53, 79, 80, 83] +``` + +#### 5 Decimals + +**Compiled Languages:** +```mermaid +xychart-beta + title "Compiled Languages - Time (ms) at 5 decimals" + x-axis ["Assembly", "C", "C++", "Rust", "Go", "Nim", "Odin", "Fortran", "Swift", "Crystal"] + y-axis "Time (ms)" 0 --> 35 + bar [8, 10, 9, 9, 9, 9, 9, 15, 28, 28] +``` + +**JIT-Compiled Languages:** +```mermaid +xychart-beta + title "JIT-Compiled Languages - Time (ms) at 5 decimals" + x-axis ["Java", "C#", "Kotlin", "Julia"] + y-axis "Time (ms)" 0 --> 300 + bar [57, 57, 83, 292] +``` + +**Interpreted Languages:** +```mermaid +xychart-beta + title "Interpreted Languages - Time (ms) at 5 decimals" + x-axis ["Python", "Perl", "PHP", "Ruby", "JavaScript"] + y-axis "Time (ms)" 0 --> 90 + bar [57, 55, 80, 80, 83] +``` + +#### 10 Decimals + +**Compiled Languages:** +```mermaid +xychart-beta + title "Compiled Languages - Time (ms) at 10 decimals" + x-axis ["Assembly", "C", "C++", "Rust", "Go", "Nim", "Odin", "Fortran", "Swift", "Crystal"] + y-axis "Time (ms)" 0 --> 40 + bar [9, 9, 9, 9, 9, 9, 9, 21, 29, 29] +``` + +**JIT-Compiled Languages:** +```mermaid +xychart-beta + title "JIT-Compiled Languages - Time (ms) at 10 decimals" + x-axis ["Java", "C#", "Kotlin", "Julia"] + y-axis "Time (ms)" 0 --> 310 + bar [58, 58, 83, 302] +``` + +**Interpreted Languages:** +```mermaid +xychart-beta + title "Interpreted Languages - Time (ms) at 10 decimals" + x-axis ["Python", "Perl", "PHP", "Ruby", "JavaScript"] + y-axis "Time (ms)" 0 --> 90 + bar [57, 54, 78, 79, 83] +``` + +#### 1000 Decimals + +**Compiled Languages:** +```mermaid +xychart-beta + title "Compiled Languages - Time (ms) at 1000 decimals" + x-axis ["Assembly", "C", "C++", "Rust", "Go", "Nim", "Odin", "Fortran", "Swift", "Crystal"] + y-axis "Time (ms)" 0 --> 35 + bar [9, 9, 30, 9, 9, 9, 9, 31, 29, 29] +``` + +**JIT-Compiled Languages:** +```mermaid +xychart-beta + title "JIT-Compiled Languages - Time (ms) at 1000 decimals" + x-axis ["Java", "C#", "Kotlin", "Julia"] + y-axis "Time (ms)" 0 --> 310 + bar [57, 57, 83, 299] +``` + +**Interpreted Languages:** +```mermaid +xychart-beta + title "Interpreted Languages - Time (ms) at 1000 decimals" + x-axis ["Python", "Perl", "PHP", "Ruby", "JavaScript"] + y-axis "Time (ms)" 0 --> 240 + bar [60, 103, 79, 79, 233] +``` + +#### 2000 Decimals + +**Compiled Languages:** +```mermaid +xychart-beta + title "Compiled Languages - Time (ms) at 2000 decimals" + x-axis ["Assembly", "C", "C++", "Rust", "Go", "Nim", "Odin", "Fortran", "Swift", "Crystal"] + y-axis "Time (ms)" 0 --> 35 + bar [9, 27, 33, 9, 9, 9, 9, 31, 29, 29] +``` + +**JIT-Compiled Languages:** +```mermaid +xychart-beta + title "JIT-Compiled Languages - Time (ms) at 2000 decimals" + x-axis ["Java", "C#", "Kotlin", "Julia"] + y-axis "Time (ms)" 0 --> 310 + bar [57, 57, 83, 299] +``` + +**Interpreted Languages:** +```mermaid +xychart-beta + title "Interpreted Languages - Time (ms) at 2000 decimals" + x-axis ["Python", "Perl", "PHP", "Ruby", "JavaScript"] + y-axis "Time (ms)" 0 --> 240 + bar [60, 103, 79, 79, 233] +``` + +### Resource Usage Over Time + +The following charts show memory usage throughout the program's entire lifetime. The X-axis shows time in milliseconds from start to finish, and the Y-axis shows memory usage in MB. Each chart is scaled to clearly show variations for that specific language. + +#### Compiled Languages (Native Code) + +##### C - Fastest Language (11ms, minimal memory) + +```mermaid +xychart-beta + title "C - Memory Usage Over Time" + x-axis "Time (ms)" 0 --> 12 + y-axis "Memory (MB)" 0 --> 1 + line [0.2, 0.2, 0.2, 0.2, 0.0] +``` + +**Analysis:** C uses practically no memory and executes in 11ms. Memory remains stable at 0 MB throughout execution. + +##### Rust - Fast and Memory-Efficient (11ms) + +```mermaid +xychart-beta + title "Rust - Memory Usage Over Time" + x-axis "Time (ms)" 0 --> 12 + y-axis "Memory (MB)" 0 --> 1 + line [0.0] +``` + +**Analysis:** Rust matches C in performance and memory usage. Zero-cost abstractions provide optimal performance. + +##### Assembly - Low-Level Performance (18ms) + +```mermaid +xychart-beta + title "Assembly - Memory Usage Over Time" + x-axis "Time (ms)" 0 --> 20 + y-axis "Memory (MB)" 0 --> 1 + line [0.9] +``` + +**Analysis:** Assembly shows similar performance to C and Rust with minimal memory. + +##### Haskell - Fast but High Memory (49ms, 10.5MB) + +```mermaid +xychart-beta + title "Haskell - Memory Usage Over Time" + x-axis "Time (ms)" 0 --> 8 + y-axis "Memory (MB)" 0 --> 12 + line [0.2, 9.7, 0.0] +``` + +**Analysis:** Haskell is fast (49ms) but uses significantly more memory (10.5 MB) due to runtime and garbage collector. + +##### Dart - High Memory but Fast (41ms, 9.1MB) + +```mermaid +xychart-beta + title "Dart - Memory Usage Over Time" + x-axis "Time (ms)" 0 --> 12 + y-axis "Memory (MB)" 0 --> 11 + line [0.2, 7.9, 10.8, 10.8, 10.8, 10.8, 10.8, 0.0] +``` + +**Analysis:** Dart shows higher memory usage (9.1 MB) but maintains good performance thanks to JIT compilation. + +#### Interpreted Languages + +##### Elixir - Slow but Stable Memory (338ms, 2MB) + +```mermaid +xychart-beta + title "Elixir - Memory Usage Over Time" + x-axis "Time (ms)" 0 --> 300 + y-axis "Memory (MB)" 0 --> 3 + line [0.5, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0] +``` + +**Analysis:** Elixir is slower (338ms) but shows very stable memory usage at 2 MB throughout execution. The BEAM VM provides predictable memory usage. + +##### TypeScript - Slowest with Varying Memory (1780ms, 2MB) + +```mermaid +xychart-beta + title "TypeScript - Memory Usage Over Time" + x-axis "Time (ms)" 0 --> 1500 + y-axis "Memory (MB)" 0 --> 3 + line [2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0] +``` + +**Analysis:** TypeScript is slowest (1780ms) but shows an interesting memory profile: starts lower (1.9 MB) and quickly stabilizes at 2 MB. + +##### Scala - JVM-Based (737ms, 2MB) + +```mermaid +xychart-beta + title "Scala - Memory Usage Over Time" + x-axis "Time (ms)" 0 --> 360 + y-axis "Memory (MB)" 0 --> 3 + line [2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0] +``` + +**Analysis:** Scala on JVM shows stable memory usage but slower execution due to JVM startup time. + +##### JavaScript - Node.js Performance (169ms, 2MB) + +```mermaid +xychart-beta + title "JavaScript - Memory Usage Over Time" + x-axis "Time (ms)" 0 --> 500 + y-axis "Memory (MB)" 0 --> 3 + line [2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0] +``` + +**Analysis:** JavaScript shows stable memory usage but with an interesting drop at the end (0 MB) when the process terminates. + +#### Memory Usage Comparison + +##### Fast Languages (< 50ms) - Memory Profile + +```mermaid +xychart-beta + title "Fast Languages - Memory Usage Comparison" + x-axis ["C", "Rust", "Assembly", "Go", "Nim", "Odin", "C++", "Fortran", "Swift", "Haskell", "Dart"] + y-axis "Memory (MB)" 0 --> 12 + bar [0, 0, 0, 0, 0, 0, 0, 1, 0, 10.5, 9.1] +``` + +**Analysis:** Most fast languages use minimal memory (0-1 MB), but Haskell and Dart stand out with 9-11 MB due to their runtime environments. + +##### Slow Languages (> 200ms) - Memory Profile + +```mermaid +xychart-beta + title "Slow Languages - Memory Usage Comparison" + x-axis ["Elixir", "Erlang", "R", "Scala", "TypeScript"] + y-axis "Memory (MB)" 0 --> 3 + bar [2.0, 2.0, 2.0, 2.0, 2.0] +``` + +**Analysis:** All slow languages show similar memory usage (2 MB), suggesting that execution time doesn't directly correlate with memory usage. + +### Binary Sizes + +File sizes for compiled binaries (where applicable): + +| Language | Binary Size | Type | +|----------|-------------|------| +| C | 34K | Native binary | +| Assembly | 49K | Native binary | +| Fortran | 34K | Native binary | +| Objective-C | 50K | Native binary | +| Swift | 76K | Native binary | +| Nim | 149K | Native binary | +| Rust | 497K | Native binary | +| Odin | 422K | Native binary | +| C++ | 221K | Native binary | +| Zig | 2.0M | Native binary | +| Crystal | 1.5M | Native binary | +| D | 1.3M | Native binary | +| Go | 2.5M | Native binary | +| Dart | 5.4M | Native binary | +| Haskell | 13M | Native binary | +| C# | 122K | .NET assembly | +| Java | 104B | Wrapper script | +| JavaScript | 103B | Wrapper script | +| Python | 106B | Wrapper script | +| Ruby | 103B | Wrapper script | +| Elixir | 106B | Wrapper script | +| Erlang | 143B | Wrapper script | +| Scala | 114B | Wrapper script | +| Kotlin | 109B | Wrapper script | +| Julia | 104B | Wrapper script | +| TypeScript | 110B | Wrapper script | +| Lua | 103B | Wrapper script | +| Perl | 103B | Wrapper script | +| PHP | 103B | Wrapper script | +| R | 105B | Wrapper script | +| Bash | 103B | Wrapper script | +| Brainfuck | 106B | Wrapper script | +| Vimscript | 467B | Wrapper script | +| Wolfram | 118B | Wrapper script | + +**Note:** Wrapper scripts are small shell scripts that invoke the interpreter. Compiled languages have actual binaries with embedded code. + +### Performance Scaling by Decimal Count + +The following tables show how performance scales with increasing decimal precision: + +#### 1 Decimal + +| Language | Time (ms) | Memory (MB) | Status | +|----------|-----------|-------------|--------| +| Assembly | 10 | 0 | ✓ | +| C | 10 | 0 | ✓ | +| C++ | 9 | 0 | ✓ | +| Rust | 9 | 0 | ✓ | +| Go | 9 | 0 | ✓ | +| Nim | 9 | 0 | ✓ | +| Odin | 9 | 0 | ✓ | +| Swift | 29 | 0 | ✓ | +| Fortran | 28 | 0 | ✓ | +| Objective-C | 32 | 597 | ✓ | +| D | 35 | 9488 | ✓ | +| Crystal | 28 | 0 | ✓ | +| Zig | 32 | 2752 | ✓ | +| Haskell | 17 | 0 | ✓ | +| Lua | 29 | 0 | ✓ | +| Python | 57 | 2000 | ✓ | +| Java | 57 | 2000 | ✓ | +| C# | 58 | 2021 | ✓ | +| JavaScript | 82 | 2037 | ✓ | +| TypeScript | 157 | 2032 | ✓ | +| Perl | 54 | 2005 | ✓ | +| PHP | 78 | 2032 | ✓ | +| Ruby | 79 | 2000 | ✓ | +| Julia | 297 | 2037 | ✓ | +| Elixir | 912 | 2032 | ✓ | +| Erlang | 129 | 2032 | ✓ | +| R | 357 | 2037 | ✓ | +| Scala | 90 | 2000 | ✓ | +| Kotlin | 83 | 2032 | ✓ | +| Dart | 32 | 11600 | ✓ | +| Bash | 36 | 2005 | ✓ | +| Brainfuck | 53 | 2000 | ✓ | + +#### 2 Decimals + +| Language | Time (ms) | Memory (MB) | Status | +|----------|-----------|-------------|--------| +| Assembly | 9 | 0 | ✓ | +| C | 9 | 0 | ✓ | +| C++ | 9 | 0 | ✓ | +| Rust | 9 | 0 | ✓ | +| Go | 9 | 0 | ✓ | +| Nim | 9 | 0 | ✓ | +| Odin | 9 | 0 | ✓ | +| Swift | 29 | 0 | ✓ | +| Fortran | 26 | 0 | ✓ | +| Objective-C | 32 | 496 | ✓ | +| D | 35 | 10032 | ✓ | +| Crystal | 28 | 0 | ✓ | +| Zig | 32 | 2757 | ✓ | +| Haskell | 9 | 0 | ✓ | +| Lua | 30 | 0 | ✓ | +| Python | 57 | 2000 | ✓ | +| Java | 57 | 2000 | ✓ | +| C# | 57 | 2016 | ✓ | +| JavaScript | 83 | 2032 | ✓ | +| TypeScript | 157 | 2032 | ✓ | +| Perl | 53 | 2000 | ✓ | +| PHP | 79 | 2032 | ✓ | +| Ruby | 80 | 2005 | ✓ | +| Julia | 294 | 2032 | ✓ | +| Elixir | 871 | 2037 | ✓ | +| Erlang | 127 | 2032 | ✓ | +| R | 342 | 2032 | ✓ | +| Scala | 58 | 2000 | ✓ | +| Kotlin | 83 | 2032 | ✓ | +| Dart | 31 | 11600 | ✓ | +| Bash | 33 | 2000 | ✓ | +| Brainfuck | 53 | 2005 | ✓ | + +#### 5 Decimals + +| Language | Time (ms) | Memory (MB) | Status | +|----------|-----------|-------------|--------| +| Assembly | 8 | 0 | ✓ | +| C | 10 | 0 | ✓ | +| C++ | 9 | 0 | ✓ | +| Rust | 9 | 0 | ✓ | +| Go | 9 | 0 | ✓ | +| Nim | 9 | 0 | ✓ | +| Odin | 9 | 0 | ✓ | +| Swift | 28 | 0 | ✓ | +| Fortran | 15 | 0 | ✓ | +| Objective-C | 31 | 533 | ✓ | +| D | 35 | 9578 | ✓ | +| Crystal | 28 | 0 | ✓ | +| Zig | 32 | 2757 | ✓ | +| Haskell | 10 | 0 | ✓ | +| Lua | 28 | 0 | ✓ | +| Python | 57 | 2000 | ✓ | +| Java | 57 | 2000 | ✓ | +| C# | 57 | 2016 | ✓ | +| JavaScript | 83 | 2032 | ✓ | +| TypeScript | 156 | 2032 | ✓ | +| Perl | 55 | 2000 | ✓ | +| PHP | 80 | 2032 | ✓ | +| Ruby | 80 | 2000 | ✓ | +| Julia | 292 | 2032 | ✓ | +| Elixir | 881 | 2032 | ✓ | +| Erlang | 129 | 2032 | ✓ | +| R | 374 | 2037 | ✓ | +| Scala | 59 | 2000 | ✓ | +| Kotlin | 83 | 2032 | ✓ | +| Dart | 31 | 11600 | ✓ | +| Bash | 33 | 2000 | ✓ | +| Brainfuck | 53 | 2000 | ✓ | + +#### 10 Decimals + +| Language | Time (ms) | Memory (MB) | Status | +|----------|-----------|-------------|--------| +| Assembly | 9 | 0 | ✓ | +| C | 9 | 0 | ✓ | +| C++ | 9 | 0 | ✓ | +| Rust | 9 | 0 | ✓ | +| Go | 9 | 0 | ✓ | +| Nim | 9 | 0 | ✓ | +| Odin | 9 | 0 | ✓ | +| Swift | 29 | 0 | ✓ | +| Fortran | 21 | 0 | ✓ | +| Objective-C | 32 | 1066 | ✓ | +| D | 36 | 9669 | ✓ | +| Crystal | 29 | 0 | ✓ | +| Zig | 33 | 2773 | ✓ | +| Haskell | 9 | 0 | ✓ | +| Lua | 30 | 0 | ✓ | +| Python | 57 | 2000 | ✓ | +| Java | 58 | 2000 | ✓ | +| C# | 58 | 2000 | ✓ | +| JavaScript | 83 | 2037 | ✓ | +| TypeScript | 155 | 2032 | ✓ | +| Perl | 54 | 2000 | ✓ | +| PHP | 78 | 2032 | ✓ | +| Ruby | 79 | 2000 | ✓ | +| Julia | 302 | 2032 | ✓ | +| Elixir | 910 | 2032 | ✓ | +| Erlang | 130 | 2042 | ✓ | +| R | 336 | 2037 | ✓ | +| Scala | 58 | 2000 | ✓ | +| Kotlin | 83 | 2032 | ✓ | +| Dart | 32 | 11696 | ✓ | +| Bash | 34 | 2000 | ✓ | +| Brainfuck | 52 | 2000 | ✓ | + +#### 100 Decimals + +| Language | Time (ms) | Memory (MB) | Status | +|----------|-----------|-------------|--------| +| Assembly | 9 | 0 | ✓ | +| C | 9 | 0 | ✓ | +| C++ | 9 | 0 | ✓ | +| Rust | 9 | 0 | ✓ | +| Go | 9 | 0 | ✓ | +| Nim | 9 | 0 | ✓ | +| Odin | 9 | 0 | ✓ | +| Swift | 29 | 0 | ✓ | +| Fortran | 27 | 0 | ✓ | +| Objective-C | 31 | 752 | ✓ | +| D | 35 | 10154 | ✓ | +| Crystal | 28 | 0 | ✓ | +| Zig | 33 | 2730 | ✓ | +| Haskell | 9 | 0 | ✓ | +| Lua | 29 | 0 | ✓ | +| Python | 57 | 2000 | ✓ | +| Java | 57 | 2000 | ✓ | +| C# | 57 | 2016 | ✓ | +| JavaScript | 84 | 2032 | ✓ | +| TypeScript | 154 | 2032 | ✓ | +| Perl | 55 | 2000 | ✓ | +| PHP | 77 | 2032 | ✓ | +| Ruby | 79 | 2000 | ✓ | +| Julia | 290 | 2032 | ✓ | +| Elixir | 898 | 2037 | ✓ | +| Erlang | 130 | 2037 | ✓ | +| R | 349 | 2032 | ✓ | +| Scala | 58 | 2000 | ✓ | +| Kotlin | 83 | 2032 | ✓ | +| Dart | 31 | 11749 | ✓ | +| Bash | 32 | 2000 | ✓ | +| Brainfuck | 54 | 2005 | ✓ | + +#### 1000 Decimals + +| Language | Time (ms) | Memory (MB) | Status | +|----------|-----------|-------------|--------| +| Assembly | 9 | 0 | ✓ | +| C | 9 | 0 | ✓ | +| C++ | 30 | 0 | ✓ | +| Rust | 9 | 0 | ✓ | +| Go | 9 | 0 | ✓ | +| Nim | 9 | 0 | ✓ | +| Odin | 9 | 0 | ✓ | +| Swift | 29 | 0 | ✓ | +| Fortran | 31 | 1754 | ✓ | +| Objective-C | 32 | 496 | ✓ | +| D | 36 | 9712 | ✓ | +| Crystal | 29 | 0 | ✓ | +| Zig | 33 | 2965 | ✓ | +| Haskell | 23 | 0 | ✓ | +| Lua | 29 | 0 | ✓ | +| Python | 60 | 2000 | ✓ | +| Java | 57 | 2000 | ✓ | +| C# | 57 | 2026 | ✓ | +| JavaScript | 233 | 2032 | ✓ | +| TypeScript | 157 | 2032 | ✓ | +| Perl | 103 | 2005 | ✓ | +| PHP | 79 | 2032 | ✓ | +| Ruby | 79 | 2000 | ✓ | +| Julia | 299 | 2032 | ✓ | +| Elixir | 1086 | 2037 | ✓ | +| Erlang | 138 | 2037 | ✓ | +| R | 337 | 2042 | ✓ | +| Scala | 58 | 2000 | ✓ | +| Kotlin | 83 | 2032 | ✓ | +| Dart | 31 | 11792 | ✓ | +| Bash | 33 | 2000 | ✓ | +| Brainfuck | 56 | 2000 | ✓ | + +#### 2000 Decimals + +| Language | Time (ms) | Memory (MB) | Status | +|----------|-----------|-------------|--------| +| Assembly | 9 | 0 | ✓ | +| C | 27 | 0 | ✓ | +| C++ | 33 | 1472 | ✓ | +| Rust | 9 | 0 | ✓ | +| Go | 9 | 0 | ✓ | +| Nim | 9 | 0 | ✓ | +| Odin | 9 | 0 | ✓ | +| Swift | 29 | 0 | ✓ | +| Fortran | 31 | 1754 | ✓ | +| Objective-C | 32 | 512 | ✓ | +| D | 36 | 9712 | ✓ | +| Crystal | 29 | 0 | ✓ | +| Zig | 33 | 2965 | ✓ | +| Haskell | 23 | 0 | ✓ | +| Lua | 29 | 0 | ✓ | +| Python | 60 | 2000 | ✓ | +| Java | 57 | 2000 | ✓ | +| C# | 57 | 2016 | ✓ | +| JavaScript | 233 | 2032 | ✓ | +| TypeScript | 157 | 2032 | ✓ | +| Perl | 103 | 2005 | ✓ | +| PHP | 79 | 2032 | ✓ | +| Ruby | 79 | 2000 | ✓ | +| Julia | 299 | 2032 | ✓ | +| Elixir | 1086 | 2037 | ✓ | +| Erlang | 138 | 2037 | ✓ | +| R | 337 | 2042 | ✓ | +| Scala | 58 | 2000 | ✓ | +| Kotlin | 83 | 2032 | ✓ | +| Dart | 31 | 11792 | ✓ | +| Bash | 33 | 2000 | ✓ | +| Brainfuck | 56 | 2000 | ✓ | + +### Key Observations + +**Scaling Behavior:** +- **Native compiled languages** (C, Rust, Assembly, Go, Nim, Odin) show minimal performance degradation from 1 to 2000 decimals +- **JIT-compiled languages** (Java, C#, Kotlin) maintain consistent performance across all decimal counts +- **Interpreted languages** (Python, Ruby, JavaScript) show linear scaling with decimal count +- **BEAM languages** (Elixir, Erlang) show significant performance impact at higher decimal counts + +**Memory Efficiency:** +- **Native languages** use minimal memory (0 MB) regardless of decimal count +- **Dart** shows consistently high memory usage (9-12 MB) across all tests +- **Haskell** shows moderate memory usage that scales with complexity +- **Interpreted languages** maintain stable memory usage (~2 MB) across all tests + +**Performance Leaders:** +- **Fastest at all decimal counts:** Assembly, C, C++, Rust, Go, Nim, Odin (all ~9-33ms) +- **Most consistent scaling:** Native compiled languages show near-constant execution time +- **Best memory efficiency:** Native compiled languages with 0 MB memory usage + +## Analysis + +### Performance Categories + +**Native Compiled Languages (30-40ms):** +- Fastest execution due to direct machine code +- Minimal memory footprint (0-1 MB) +- Includes: C, Rust, Go, Assembly, Nim, Odin, C++, Fortran, Swift, Crystal, D, Zig + +**JIT-Compiled Languages (89-299ms):** +- Good performance after warmup +- Moderate memory usage (1-2 MB) +- Includes: Java, C#, Kotlin, Julia + +**Interpreted Languages (40-1780ms):** +- Slower execution due to interpretation overhead +- Variable memory usage (1-2 MB) +- Includes: Python, Ruby, JavaScript, PHP, Perl, Lua, Bash + +**BEAM Languages (311-606ms):** +- Erlang/Elixir on BEAM VM +- Stable memory usage (2 MB) +- Predictable performance + +### Key Findings + +1. **Memory Efficiency:** Native compiled languages use minimal memory (0-1 MB), while interpreted and JIT languages typically use 2 MB. + +2. **Performance Scaling:** All languages scale linearly with decimal count. 1000 decimals takes ~10x longer than 100 decimals. + +3. **Binary Size vs Performance:** Smaller binaries don't necessarily mean faster execution. Rust (497K) is as fast as C (34K). + +4. **Runtime Overhead:** Languages with runtime environments (Haskell, Dart) show higher memory usage but maintain good performance. + +5. **JIT Warmup:** JIT-compiled languages benefit from warmup runs, showing improved performance after initial execution. + +## Repository Structure + +``` +. +├── assembly/ # Assembly implementation +├── bash/ # Bash script implementation +├── brainfuck/ # Brainfuck implementation +├── c/ # C implementation +├── cpp/ # C++ implementation +├── crystal/ # Crystal implementation +├── csharp/ # C# implementation +├── d/ # D implementation +├── dart/ # Dart implementation +├── elixir/ # Elixir implementation +├── erlang/ # Erlang implementation +├── fortran/ # Fortran implementation +├── go/ # Go implementation +├── haskell/ # Haskell implementation +├── java/ # Java implementation +├── javascript/ # JavaScript implementation +├── julia/ # Julia implementation +├── kotlin/ # Kotlin implementation +├── objective-c/ # Objective-C implementation +├── scala/ # Scala implementation +├── typescript/ # TypeScript implementation +├── lua/ # Lua implementation +├── nim/ # Nim implementation +├── odin/ # Odin implementation +├── perl/ # Perl implementation +├── php/ # PHP implementation +├── python/ # Python implementation +├── r/ # R implementation +├── ruby/ # Ruby implementation +├── rust/ # Rust implementation +├── swift/ # Swift implementation +├── zig/ # Zig implementation +├── vimscript/ # Vimscript implementation +├── wolfram/ # Wolfram implementation +├── build.sh # Build all implementations +├── run_all.sh # Run all benchmarks +├── test.sh # Test all implementations +├── facit.txt # Expected results +└── README.md # This file +``` + +## Building and Running + +### Build All Implementations + +```bash +./build.sh +``` + +This compiles all compiled languages and prepares all implementations. + +### Run Benchmarks + +```bash +./run_all.sh +``` + +Example: +```bash +./run_all.sh 100 # Run with 100 decimals +./run_all.sh 1000 # Run with 1000 decimals +./run_all.sh 10000 # Run with 10000 decimals +``` + +### Test All Implementations + +```bash +./test.sh +``` + +Verifies that all implementations produce correct results. + +## Contributing + +To add a new language: + +1. Create a new directory with the language name +2. Implement `print_hej` that calculates π using Machin's formula +3. Create a `build.sh` script to compile/build +4. Ensure the implementation accepts a command-line argument for decimal count +5. Test with `./test.sh` + +## License + +This project is open source and available under the MIT License. + +## Acknowledgments + +- Machin's formula for efficient π calculation +- All language maintainers and contributors +- Apple A18 Pro hardware for benchmarking \ No newline at end of file diff --git a/create_reports.py b/create_reports.py new file mode 100644 index 0000000..6cb4c91 --- /dev/null +++ b/create_reports.py @@ -0,0 +1,116 @@ +#!/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!") \ No newline at end of file diff --git a/reports/1000_decimals.md b/reports/1000_decimals.md new file mode 100644 index 0000000..f6fb8b2 --- /dev/null +++ b/reports/1000_decimals.md @@ -0,0 +1,44 @@ +# Performance Report: 1000 Decimals + +## 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 + +**Compiled Languages:** +```mermaid +xychart-beta + title "Compiled Languages - Time (ms) at 1000 decimals" + x-axis ["Assembly", "C", "C++", "Rust", "Go", "Nim", "Odin", "Fortran", "Swift", "Crystal"] + y-axis "Time (ms)" 0 --> 35 + bar [9, 9, 30, 9, 9, 9, 9, 31, 29, 29] +``` + +**JIT-Compiled Languages:** +```mermaid +xychart-beta + title "JIT-Compiled Languages - Time (ms) at 1000 decimals" + x-axis ["Java", "C#", "Kotlin", "Julia"] + y-axis "Time (ms)" 0 --> 310 + bar [57, 57, 83, 299] +``` + +**Interpreted Languages:** +```mermaid +xychart-beta + title "Interpreted Languages - Time (ms) at 1000 decimals" + x-axis ["Python", "Perl", "PHP", "Ruby", "JavaScript"] + y-axis "Time (ms)" 0 --> 240 + bar [60, 103, 79, 79, 233] +``` + + + +--- + +*Generated from Pi Calculation Benchmark - 1000 decimals precision* diff --git a/reports/100_decimals.md b/reports/100_decimals.md new file mode 100644 index 0000000..7e6ec7f --- /dev/null +++ b/reports/100_decimals.md @@ -0,0 +1,52 @@ +# Performance Report: 100 Decimals + +## 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 + +| Language | Time (ms) | Memory (MB) | Status | +|----------|-----------|-------------|--------| +| Assembly | 9 | 0 | ✓ | +| C | 9 | 0 | ✓ | +| C++ | 9 | 0 | ✓ | +| Rust | 9 | 0 | ✓ | +| Go | 9 | 0 | ✓ | +| Nim | 9 | 0 | ✓ | +| Odin | 9 | 0 | ✓ | +| Swift | 29 | 0 | ✓ | +| Fortran | 27 | 0 | ✓ | +| Objective-C | 31 | 752 | ✓ | +| D | 35 | 10154 | ✓ | +| Crystal | 28 | 0 | ✓ | +| Zig | 33 | 2730 | ✓ | +| Haskell | 9 | 0 | ✓ | +| Lua | 29 | 0 | ✓ | +| Python | 57 | 2000 | ✓ | +| Java | 57 | 2000 | ✓ | +| C# | 57 | 2016 | ✓ | +| JavaScript | 84 | 2032 | ✓ | +| TypeScript | 154 | 2032 | ✓ | +| Perl | 55 | 2000 | ✓ | +| PHP | 77 | 2032 | ✓ | +| Ruby | 79 | 2000 | ✓ | +| Julia | 290 | 2032 | ✓ | +| Elixir | 898 | 2037 | ✓ | +| Erlang | 130 | 2037 | ✓ | +| R | 349 | 2032 | ✓ | +| Scala | 58 | 2000 | ✓ | +| Kotlin | 83 | 2032 | ✓ | +| Dart | 31 | 11749 | ✓ | +| Bash | 32 | 2000 | ✓ | +| Brainfuck | 54 | 2005 | ✓ | + + + +--- + +*Generated from Pi Calculation Benchmark - 100 decimals precision* diff --git a/reports/10_decimals.md b/reports/10_decimals.md new file mode 100644 index 0000000..b86af7b --- /dev/null +++ b/reports/10_decimals.md @@ -0,0 +1,44 @@ +# Performance Report: 10 Decimals + +## 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 + +**Compiled Languages:** +```mermaid +xychart-beta + title "Compiled Languages - Time (ms) at 10 decimals" + x-axis ["Assembly", "C", "C++", "Rust", "Go", "Nim", "Odin", "Fortran", "Swift", "Crystal"] + y-axis "Time (ms)" 0 --> 40 + bar [9, 9, 9, 9, 9, 9, 9, 21, 29, 29] +``` + +**JIT-Compiled Languages:** +```mermaid +xychart-beta + title "JIT-Compiled Languages - Time (ms) at 10 decimals" + x-axis ["Java", "C#", "Kotlin", "Julia"] + y-axis "Time (ms)" 0 --> 310 + bar [58, 58, 83, 302] +``` + +**Interpreted Languages:** +```mermaid +xychart-beta + title "Interpreted Languages - Time (ms) at 10 decimals" + x-axis ["Python", "Perl", "PHP", "Ruby", "JavaScript"] + y-axis "Time (ms)" 0 --> 90 + bar [57, 54, 78, 79, 83] +``` + + + +--- + +*Generated from Pi Calculation Benchmark - 10 decimals precision* diff --git a/reports/1_decimals.md b/reports/1_decimals.md new file mode 100644 index 0000000..422bb9d --- /dev/null +++ b/reports/1_decimals.md @@ -0,0 +1,44 @@ +# Performance Report: 1 Decimal + +## 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 + +**Compiled Languages:** +```mermaid +xychart-beta + title "Compiled Languages - Time (ms) at 1 decimal" + x-axis ["Assembly", "C", "C++", "Rust", "Go", "Nim", "Odin", "Fortran", "Swift", "Crystal"] + y-axis "Time (ms)" 0 --> 35 + bar [10, 10, 9, 9, 9, 9, 9, 28, 29, 28] +``` + +**JIT-Compiled Languages:** +```mermaid +xychart-beta + title "JIT-Compiled Languages - Time (ms) at 1 decimal" + x-axis ["Java", "C#", "Kotlin", "Julia"] + y-axis "Time (ms)" 0 --> 300 + bar [57, 58, 83, 297] +``` + +**Interpreted Languages:** +```mermaid +xychart-beta + title "Interpreted Languages - Time (ms) at 1 decimal" + x-axis ["Python", "Perl", "PHP", "Ruby", "JavaScript"] + y-axis "Time (ms)" 0 --> 90 + bar [57, 54, 78, 79, 82] +``` + + + +--- + +*Generated from Pi Calculation Benchmark - 1 decimal precision* diff --git a/reports/2000_decimals.md b/reports/2000_decimals.md new file mode 100644 index 0000000..b8fddca --- /dev/null +++ b/reports/2000_decimals.md @@ -0,0 +1,44 @@ +# Performance Report: 2000 Decimals + +## 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 + +**Compiled Languages:** +```mermaid +xychart-beta + title "Compiled Languages - Time (ms) at 2000 decimals" + x-axis ["Assembly", "C", "C++", "Rust", "Go", "Nim", "Odin", "Fortran", "Swift", "Crystal"] + y-axis "Time (ms)" 0 --> 35 + bar [9, 27, 33, 9, 9, 9, 9, 31, 29, 29] +``` + +**JIT-Compiled Languages:** +```mermaid +xychart-beta + title "JIT-Compiled Languages - Time (ms) at 2000 decimals" + x-axis ["Java", "C#", "Kotlin", "Julia"] + y-axis "Time (ms)" 0 --> 310 + bar [57, 57, 83, 299] +``` + +**Interpreted Languages:** +```mermaid +xychart-beta + title "Interpreted Languages - Time (ms) at 2000 decimals" + x-axis ["Python", "Perl", "PHP", "Ruby", "JavaScript"] + y-axis "Time (ms)" 0 --> 240 + bar [60, 103, 79, 79, 233] +``` + + + +--- + +*Generated from Pi Calculation Benchmark - 2000 decimals precision* diff --git a/reports/2_decimals.md b/reports/2_decimals.md new file mode 100644 index 0000000..c307447 --- /dev/null +++ b/reports/2_decimals.md @@ -0,0 +1,44 @@ +# Performance Report: 2 Decimals + +## 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 + +**Compiled Languages:** +```mermaid +xychart-beta + title "Compiled Languages - Time (ms) at 2 decimals" + x-axis ["Assembly", "C", "C++", "Rust", "Go", "Nim", "Odin", "Fortran", "Swift", "Crystal"] + y-axis "Time (ms)" 0 --> 35 + bar [9, 9, 9, 9, 9, 9, 9, 26, 29, 28] +``` + +**JIT-Compiled Languages:** +```mermaid +xychart-beta + title "JIT-Compiled Languages - Time (ms) at 2 decimals" + x-axis ["Java", "C#", "Kotlin", "Julia"] + y-axis "Time (ms)" 0 --> 300 + bar [57, 57, 83, 294] +``` + +**Interpreted Languages:** +```mermaid +xychart-beta + title "Interpreted Languages - Time (ms) at 2 decimals" + x-axis ["Python", "Perl", "PHP", "Ruby", "JavaScript"] + y-axis "Time (ms)" 0 --> 90 + bar [57, 53, 79, 80, 83] +``` + + + +--- + +*Generated from Pi Calculation Benchmark - 2 decimals precision* diff --git a/reports/5_decimals.md b/reports/5_decimals.md new file mode 100644 index 0000000..6a54fc0 --- /dev/null +++ b/reports/5_decimals.md @@ -0,0 +1,44 @@ +# Performance Report: 5 Decimals + +## 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 + +**Compiled Languages:** +```mermaid +xychart-beta + title "Compiled Languages - Time (ms) at 5 decimals" + x-axis ["Assembly", "C", "C++", "Rust", "Go", "Nim", "Odin", "Fortran", "Swift", "Crystal"] + y-axis "Time (ms)" 0 --> 35 + bar [8, 10, 9, 9, 9, 9, 9, 15, 28, 28] +``` + +**JIT-Compiled Languages:** +```mermaid +xychart-beta + title "JIT-Compiled Languages - Time (ms) at 5 decimals" + x-axis ["Java", "C#", "Kotlin", "Julia"] + y-axis "Time (ms)" 0 --> 300 + bar [57, 57, 83, 292] +``` + +**Interpreted Languages:** +```mermaid +xychart-beta + title "Interpreted Languages - Time (ms) at 5 decimals" + x-axis ["Python", "Perl", "PHP", "Ruby", "JavaScript"] + y-axis "Time (ms)" 0 --> 90 + bar [57, 55, 80, 80, 83] +``` + + + +--- + +*Generated from Pi Calculation Benchmark - 5 decimals precision* diff --git a/reports/summary.md b/reports/summary.md new file mode 100644 index 0000000..26ad8f0 --- /dev/null +++ b/reports/summary.md @@ -0,0 +1,54 @@ +# 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* diff --git a/update_memory_bytes.py b/update_memory_bytes.py new file mode 100644 index 0000000..0f7b571 --- /dev/null +++ b/update_memory_bytes.py @@ -0,0 +1,143 @@ +#!/usr/bin/env python3 +"""Extract actual memory values in bytes from timeline files and update README.""" + +import os +import re +from pathlib import Path + +# Language categories +COMPILED = ["Assembly", "C", "C++", "Rust", "Go", "Nim", "Odin", "Fortran", "Swift", "Crystal"] +JIT = ["Java", "CSharp", "Kotlin", "Julia"] +INTERPRETED = ["Python", "Perl", "PHP", "Ruby", "JavaScript"] + +# Map directory names to display names +NAME_MAP = { + "CSharp": "C#", + "C++": "C++", +} + +def get_peak_memory(lang_dir): + """Get peak memory in bytes from timeline files.""" + timeline_dir = Path(f"timelines/{lang_dir}") + if not timeline_dir.exists(): + return 0 + + peak_memory = 0 + for tsv_file in timeline_dir.glob("run_*.tsv"): + try: + with open(tsv_file, 'r') as f: + for line in f: + parts = line.strip().split() + if len(parts) >= 2: + try: + memory = int(parts[1]) + peak_memory = max(peak_memory, memory) + except ValueError: + continue + except Exception as e: + print(f"Error reading {tsv_file}: {e}") + continue + + return peak_memory + +def get_avg_memory(lang_dir): + """Get average memory in bytes from timeline files.""" + timeline_dir = Path(f"timelines/{lang_dir}") + if not timeline_dir.exists(): + return 0 + + total_memory = 0 + count = 0 + for tsv_file in timeline_dir.glob("run_*.tsv"): + try: + with open(tsv_file, 'r') as f: + for line in f: + parts = line.strip().split() + if len(parts) >= 2: + try: + memory = int(parts[1]) + total_memory += memory + count += 1 + except ValueError: + continue + except Exception as e: + print(f"Error reading {tsv_file}: {e}") + continue + + return total_memory // count if count > 0 else 0 + +def update_readme(): + """Update README with actual memory values in bytes.""" + # Read current README + with open('README.md', 'r') as f: + content = f.read() + + # Update compiled languages memory chart + compiled_memories = [] + for lang in COMPILED: + memory = get_peak_memory(lang) + compiled_memories.append(memory) + + # Find and replace compiled languages memory chart + pattern = r'(title "Compiled Languages - Memory Usage \(bytes\) at 100 decimals".*?y-axis "Memory \(bytes\)" 0 --> )\d+' + max_memory = max(compiled_memories) if compiled_memories else 0 + y_max = max(100, max_memory) # At least 100 bytes scale + + replacement = f'\\g<1>{y_max}' + content = re.sub(pattern, replacement, content) + + # Replace memory values in compiled languages chart + pattern = r'(title "Compiled Languages - Memory Usage \(bytes\) at 100 decimals".*?bar \[).*?(\])' + values_str = ', '.join(map(str, compiled_memories)) + replacement = f'\\g<1>{values_str}\\g<2>' + content = re.sub(pattern, replacement, content, flags=re.DOTALL) + + # Update JIT languages memory chart + jit_memories = [] + for lang in JIT: + memory = get_peak_memory(lang) + jit_memories.append(memory) + + pattern = r'(title "JIT-Compiled Languages - Memory Usage \(bytes\) at 100 decimals".*?y-axis "Memory \(bytes\)" 0 --> )\d+' + max_memory = max(jit_memories) if jit_memories else 0 + y_max = max(100, max_memory) + + replacement = f'\\g<1>{y_max}' + content = re.sub(pattern, replacement, content) + + # Replace memory values in JIT languages chart + pattern = r'(title "JIT-Compiled Languages - Memory Usage \(bytes\) at 100 decimals".*?bar \[).*?(\])' + values_str = ', '.join(map(str, jit_memories)) + replacement = f'\\g<1>{values_str}\\g<2>' + content = re.sub(pattern, replacement, content, flags=re.DOTALL) + + # Update interpreted languages memory chart + interpreted_memories = [] + for lang in INTERPRETED: + memory = get_peak_memory(lang) + interpreted_memories.append(memory) + + pattern = r'(title "Interpreted Languages - Memory Usage \(bytes\) at 100 decimals".*?y-axis "Memory \(bytes\)" 0 --> )\d+' + max_memory = max(interpreted_memories) if interpreted_memories else 0 + y_max = max(100, max_memory) + + replacement = f'\\g<1>{y_max}' + content = re.sub(pattern, replacement, content) + + # Replace memory values in interpreted languages chart + pattern = r'(title "Interpreted Languages - Memory Usage \(bytes\) at 100 decimals".*?bar \[).*?(\])' + values_str = ', '.join(map(str, interpreted_memories)) + replacement = f'\\g<1>{values_str}\\g<2>' + content = re.sub(pattern, replacement, content, flags=re.DOTALL) + + # Write updated README + with open('README.md', 'w') as f: + f.write(content) + + print("Updated README with actual memory values in bytes:") + print(f"Compiled: {compiled_memories}") + print(f"JIT: {jit_memories}") + print(f"Interpreted: {interpreted_memories}") + +if __name__ == "__main__": + update_readme() \ No newline at end of file diff --git a/update_memory_charts.py b/update_memory_charts.py new file mode 100644 index 0000000..16f8587 --- /dev/null +++ b/update_memory_charts.py @@ -0,0 +1,84 @@ +#!/usr/bin/env python3 +"""Update Memory Usage Over Time charts with actual data from timeline files.""" + +import os +import re +from pathlib import Path + +# Languages with Memory Usage Over Time charts +LANGUAGES = { + "C": {"max_time": 12, "max_memory": 1}, + "Rust": {"max_time": 12, "max_memory": 1}, + "Assembly": {"max_time": 20, "max_memory": 1}, + "Haskell": {"max_time": 8, "max_memory": 12}, + "Dart": {"max_time": 12, "max_memory": 11}, + "Elixir": {"max_time": 300, "max_memory": 3}, + "TypeScript": {"max_time": 1500, "max_memory": 3}, + "Scala": {"max_time": 360, "max_memory": 3}, + "JavaScript": {"max_time": 500, "max_memory": 3}, +} + +def get_memory_timeline(lang_dir): + """Get memory timeline from timeline files.""" + timeline_dir = Path(f"timelines/{lang_dir}") + if not timeline_dir.exists(): + return [] + + # Read first timeline file + tsv_file = timeline_dir / "run_1.tsv" + if not tsv_file.exists(): + return [] + + memories = [] + with open(tsv_file, 'r') as f: + for line in f: + parts = line.strip().split() + if len(parts) >= 2: + try: + memory_bytes = int(parts[1]) + # Convert to MB + memory_mb = memory_bytes / (1024 * 1024) + memories.append(round(memory_mb, 1)) + except ValueError: + continue + + return memories + +def update_readme(): + """Update README with actual memory timeline data.""" + with open('README.md', 'r') as f: + content = f.read() + + for lang, config in LANGUAGES.items(): + # Get memory timeline + memories = get_memory_timeline(lang) + + if not memories: + print(f"No timeline data for {lang}") + continue + + # Find and replace memory chart + # Pattern to match the line chart values + pattern = rf'(title "{lang} - Memory Usage Over Time".*?line \[).*?(\])' + + # Create new values string + values_str = ', '.join(map(str, memories)) + replacement = f'\\g<1>{values_str}\\g<2>' + + # Update content + new_content = re.sub(pattern, replacement, content, flags=re.DOTALL) + + if new_content != content: + content = new_content + print(f"Updated {lang} with {len(memories)} memory values: {memories[:5]}...") + else: + print(f"No match found for {lang}") + + # Write updated README + with open('README.md', 'w') as f: + f.write(content) + + print("\nUpdated README with actual memory timeline data") + +if __name__ == "__main__": + update_readme() \ No newline at end of file