Files
print_hej/README.md
T
Ein Anderssono c4d5ed0500 Convert all memory values from MB to bytes in README
- Updated all memory charts to show bytes instead of MB
- Converted y-axis ranges from MB to bytes (e.g., 3 MB -> 3000000 bytes)
- Converted all memory values in charts (e.g., 2 MB -> 2000000 bytes)
- Updated all table headers to show 'Memory (bytes)'
- Better for comparing memory usage across all languages
2026-04-23 09:52:38 +02:00

27 KiB

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

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
    [9000000, 9000000, 9000000, 9000000, 9000000, 9000000, 9000000, 27000000, 29000000, 28000000]
xychart-beta
    title "Compiled Languages - Memory Usage (MB) at 100 decimals"
    x-axis ["Assembly", "C", "C++", "Rust", "Go", "Nim", "Odin", "Fortran", "Swift", "Crystal"]
    y-axis "Memory (bytes)" 0 --> 100
    [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

JIT-Compiled Languages

xychart-beta
    title "JIT-Compiled Languages - Time (ms) at 100 decimals"
    x-axis ["Java", "C#", "Kotlin", "Julia"]
    y-axis "Time (ms)" 0 --> 300
    [57000000, 57000000, 83000000, 290000000]
xychart-beta
    title "JIT-Compiled Languages - Memory Usage (MB) at 100 decimals"
    x-axis ["Java", "C#", "Kotlin", "Julia"]
    y-axis "Memory (bytes)" 0 --> 3000000
    [2000000, 2000000, 2000000, 2000000]

Interpreted Languages

xychart-beta
    title "Interpreted Languages - Time (ms) at 100 decimals"
    x-axis ["Python", "Perl", "PHP", "Ruby", "JavaScript"]
    y-axis "Time (ms)" 0 --> 90
    [57000000, 55000000, 77000000, 79000000, 84000000]
xychart-beta
    title "Interpreted Languages - Memory Usage (MB) at 100 decimals"
    x-axis ["Python", "Perl", "PHP", "Ruby", "JavaScript"]
    y-axis "Memory (bytes)" 0 --> 3000000
    [2000000, 2000000, 2000000, 2000000, 2000000]

Slowest Languages

xychart-beta
    title "Slowest Languages - Time (ms) at 100 decimals"
    x-axis ["Erlang", "R", "Elixir", "Scala", "TypeScript"]
    y-axis "Time (ms)" 0 --> 900
    [130000000, 349000000, 898000000, 58000000, 154000000]

Performance Scaling by Decimal Count

1 Decimal

Compiled Languages:

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
    [10000000, 10000000, 9000000, 9000000, 9000000, 9000000, 9000000, 28000000, 29000000, 28000000]

JIT-Compiled Languages:

xychart-beta
    title "JIT-Compiled Languages - Time (ms) at 1 decimal"
    x-axis ["Java", "C#", "Kotlin", "Julia"]
    y-axis "Time (ms)" 0 --> 300
    [57000000, 58000000, 83000000, 297000000]

Interpreted Languages:

xychart-beta
    title "Interpreted Languages - Time (ms) at 1 decimal"
    x-axis ["Python", "Perl", "PHP", "Ruby", "JavaScript"]
    y-axis "Time (ms)" 0 --> 90
    [57000000, 54000000, 78000000, 79000000, 82000000]

2 Decimals

Compiled Languages:

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
    [9000000, 9000000, 9000000, 9000000, 9000000, 9000000, 9000000, 26000000, 29000000, 28000000]

JIT-Compiled Languages:

xychart-beta
    title "JIT-Compiled Languages - Time (ms) at 2 decimals"
    x-axis ["Java", "C#", "Kotlin", "Julia"]
    y-axis "Time (ms)" 0 --> 300
    [57000000, 57000000, 83000000, 294000000]

Interpreted Languages:

xychart-beta
    title "Interpreted Languages - Time (ms) at 2 decimals"
    x-axis ["Python", "Perl", "PHP", "Ruby", "JavaScript"]
    y-axis "Time (ms)" 0 --> 90
    [57000000, 53000000, 79000000, 80000000, 83000000]

5 Decimals

Compiled Languages:

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
    [8000000, 10000000, 9000000, 9000000, 9000000, 9000000, 9000000, 15000000, 28000000, 28000000]

JIT-Compiled Languages:

xychart-beta
    title "JIT-Compiled Languages - Time (ms) at 5 decimals"
    x-axis ["Java", "C#", "Kotlin", "Julia"]
    y-axis "Time (ms)" 0 --> 300
    [57000000, 57000000, 83000000, 292000000]

Interpreted Languages:

xychart-beta
    title "Interpreted Languages - Time (ms) at 5 decimals"
    x-axis ["Python", "Perl", "PHP", "Ruby", "JavaScript"]
    y-axis "Time (ms)" 0 --> 90
    [57000000, 55000000, 80000000, 80000000, 83000000]

10 Decimals

Compiled Languages:

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
    [9000000, 9000000, 9000000, 9000000, 9000000, 9000000, 9000000, 21000000, 29000000, 29000000]

JIT-Compiled Languages:

xychart-beta
    title "JIT-Compiled Languages - Time (ms) at 10 decimals"
    x-axis ["Java", "C#", "Kotlin", "Julia"]
    y-axis "Time (ms)" 0 --> 310
    [58000000, 58000000, 83000000, 302000000]

Interpreted Languages:

xychart-beta
    title "Interpreted Languages - Time (ms) at 10 decimals"
    x-axis ["Python", "Perl", "PHP", "Ruby", "JavaScript"]
    y-axis "Time (ms)" 0 --> 90
    [57000000, 54000000, 78000000, 79000000, 83000000]

1000 Decimals

Compiled Languages:

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
    [9000000, 9000000, 30000000, 9000000, 9000000, 9000000, 9000000, 31000000, 29000000, 29000000]

JIT-Compiled Languages:

xychart-beta
    title "JIT-Compiled Languages - Time (ms) at 1000 decimals"
    x-axis ["Java", "C#", "Kotlin", "Julia"]
    y-axis "Time (ms)" 0 --> 310
    [57000000, 57000000, 83000000, 299000000]

Interpreted Languages:

xychart-beta
    title "Interpreted Languages - Time (ms) at 1000 decimals"
    x-axis ["Python", "Perl", "PHP", "Ruby", "JavaScript"]
    y-axis "Time (ms)" 0 --> 240
    [60000000, 103000000, 79000000, 79000000, 233000000]

2000 Decimals

Compiled Languages:

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
    [9000000, 27000000, 33000000, 9000000, 9000000, 9000000, 9000000, 31000000, 29000000, 29000000]

JIT-Compiled Languages:

xychart-beta
    title "JIT-Compiled Languages - Time (ms) at 2000 decimals"
    x-axis ["Java", "C#", "Kotlin", "Julia"]
    y-axis "Time (ms)" 0 --> 310
    [57000000, 57000000, 83000000, 299000000]

Interpreted Languages:

xychart-beta
    title "Interpreted Languages - Time (ms) at 2000 decimals"
    x-axis ["Python", "Perl", "PHP", "Ruby", "JavaScript"]
    y-axis "Time (ms)" 0 --> 240
    [60000000, 103000000, 79000000, 79000000, 233000000]

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)
xychart-beta
    title "C - Memory Usage Over Time"
    x-axis "Time (ms)" 0 --> 12
    y-axis "Memory (bytes)" 0 --> 100
    [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)
xychart-beta
    title "Rust - Memory Usage Over Time"
    x-axis "Time (ms)" 0 --> 12
    y-axis "Memory (bytes)" 0 --> 100
    [0]

Analysis: Rust matches C in performance and memory usage. Zero-cost abstractions provide optimal performance.

Assembly - Low-Level Performance (18ms)
xychart-beta
    title "Assembly - Memory Usage Over Time"
    x-axis "Time (ms)" 0 --> 20
    y-axis "Memory (bytes)" 0 --> 100
    [0]

Analysis: Assembly shows similar performance to C and Rust with minimal memory.

Haskell - Fast but High Memory (49ms, 10.5MB)
xychart-beta
    title "Haskell - Memory Usage Over Time"
    x-axis "Time (ms)" 0 --> 8
    y-axis "Memory (bytes)" 0 --> 12000000
    [10500000]

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)
xychart-beta
    title "Dart - Memory Usage Over Time"
    x-axis "Time (ms)" 0 --> 12
    y-axis "Memory (bytes)" 0 --> 11000000
    [9100000]

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)
xychart-beta
    title "Elixir - Memory Usage Over Time"
    x-axis "Time (ms)" 0 --> 300
    y-axis "Memory (bytes)" 0 --> 3000000
    [2000000, 2000000, 2000000, 2000000, 2000000, 2000000, 2000000, 2000000, 2000000, 2000000, 2000000, 2000000, 2000000]

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)
xychart-beta
    title "TypeScript - Memory Usage Over Time"
    x-axis "Time (ms)" 0 --> 1500
    y-axis "Memory (bytes)" 0 --> 3000000
    [1900000, 2000000, 2000000, 2000000, 2000000, 2000000, 2000000, 2000000, 2000000, 2000000, 2000000, 2000000, 2000000, 2000000, 2000000, 2000000, 2000000, 2000000, 2000000, 2000000, 2000000, 2000000, 2000000, 2000000, 2000000, 2000000, 2000000]

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)
xychart-beta
    title "Scala - Memory Usage Over Time"
    x-axis "Time (ms)" 0 --> 360
    y-axis "Memory (bytes)" 0 --> 3000000
    [2000000, 2000000, 2000000, 2000000, 2000000, 2000000, 2000000, 2000000, 2000000, 2000000, 2000000, 2000000, 2000000, 2000000, 2000000]

Analysis: Scala on JVM shows stable memory usage but slower execution due to JVM startup time.

JavaScript - Node.js Performance (169ms, 2MB)
xychart-beta
    title "JavaScript - Memory Usage Over Time"
    x-axis "Time (ms)" 0 --> 500
    y-axis "Memory (bytes)" 0 --> 3000000
    [2000000, 2000000, 2000000, 2000000, 2000000, 2000000, 2000000, 2000000, 2000000, 2000000, 2000000, 2000000, 2000000, 2000000, 2000000, 2000000, 2000000, 2000000, 2000000, 2000000, 2000000, 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
xychart-beta
    title "Fast Languages - Memory Usage Comparison"
    x-axis ["C", "Rust", "Assembly", "Go", "Nim", "Odin", "C++", "Fortran", "Swift", "Haskell", "Dart"]
    y-axis "Memory (bytes)" 0 --> 12000000
    [0, 0, 0, 0, 0, 0, 0, 1000000, 0, 10500000, 9100000]

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
xychart-beta
    title "Slow Languages - Memory Usage Comparison"
    x-axis ["Elixir", "Erlang", "R", "Scala", "TypeScript"]
    y-axis "Memory (bytes)" 0 --> 3000000
    [2000000, 2000000, 2000000, 2000000, 2000000]

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 (bytes) 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 (bytes) 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 (bytes) 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 (bytes) 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 (bytes) 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 (bytes) 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 (bytes) 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

./build.sh

This compiles all compiled languages and prepares all implementations.

Run Benchmarks

./run_all.sh <decimals>

Example:

./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

./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