Ein Anderssono 43870e5920 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
2026-04-23 10:16:20 +02:00

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 across multiple decimal precision levels.

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)
  • Memory measured in bytes via RSS (Resident Set Size)

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

Performance Reports

Detailed performance reports are available for each decimal precision level:

Summary Results (100 Decimals)

Fastest Languages

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

Language Categories

Compiled Languages (Native Code):

  • Fastest execution (9-29 ms)
  • Minimal memory usage (0-966,656 bytes)
  • Consistent performance across decimal levels

JIT-Compiled Languages:

  • Moderate execution time (57-290 ms)
  • Higher memory usage (~2 MB)
  • Good performance after warmup

Interpreted Languages:

  • Slower execution (55-84 ms)
  • Moderate memory usage (~2 MB)
  • Variable performance

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

Languages Tested

Compiled (10): Assembly, C, C++, Rust, Go, Nim, Odin, Fortran, Swift, Crystal

JIT-Compiled (4): Java, C#, Kotlin, Julia

Interpreted (5): Python, Perl, PHP, Ruby, JavaScript

Other (15): Bash, Brainfuck, D, Dart, Elixir, Erlang, Haskell, Lua, Objective-C, R, Scala, TypeScript, Vimscript, Wolfram, Zig

Repository Structure

.
├── 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

Running the Benchmark

# Build all languages
./build.sh

# Run all tests
./run_all.sh

# Run specific language
cd c && ./build.sh && ./print_hej

License

MIT License - See LICENSE file for details.


Generated from Pi Calculation Benchmark - Apple A18 Pro Performance Study

S
Description
No description provided
Readme 2.3 MiB
Languages
Python 32.3%
Shell 26.3%
C 5.5%
Rust 2.7%
C# 2.7%
Other 30.5%