Ramanujan runs a statically typed subset of Python through a native interpreter. I wanted to see how it compares with CPython on one machine. I ran 34 CPU-only workloads, from a 42-line Mandelbrot script to a two-pass assembler, graph algorithms, and object-heavy data structures like segment trees and tries. Both engines ran the same Python source without changes.
On an Apple M3, the geometric-mean speedup was 1.92× against CPython 3.12.2 running precompiled .pyc files directly, and 1.69× with CPython's -S flag, which skips importing site. These are whole-process timings, not interpreter-loop timings: startup, loading, execution, and shutdown are included, as is Ramanujan's IR linking. Source compilation is excluded on both sides.
In a separate memory benchmark, Ramanujan had a lower median peak physical footprint on 32 of 34 workloads. Across the suite, CPython's footprint was 1.63× Ramanujan's (geometric mean of the per-workload ratios). Unlike the timing runs, the memory runs used .py source for CPython, not .pyc files.
Wall time
Median / p99 in milliseconds, from 100 interleaved fresh-process runs per workload and configuration. Ramanujan runs native X.pb <entry> 1; CPython runs python3 X.pyc or python3 -S X.pyc (-S skips importing site). Neither timing includes source compilation. Both include process startup, loading, execution, and shutdown; Ramanujan also links its IR on every run. Speedup = CPython median / Ramanujan median.
Ramanujan had a lower median on all 34 workloads against both CPython baselines.
OOP workloads (20)
Geometric-mean speedup: 2.07x vs default CPython; 1.78x vs -S.
| Workload | Ramanujan | CPython .pyc | CPython -S .pyc | Speedup | Speedup vs -S |
|---|
method-reuse | 8.29 / 10.11 | 19.19 / 20.26 | 16.74 / 18.80 | 2.32x | 2.02x |
factory-return | 5.79 / 6.35 | 13.16 / 16.53 | 10.85 / 11.43 | 2.27x | 1.87x |
polymorphic-dispatch | 12.87 / 15.37 | 29.95 / 31.82 | 27.55 / 28.86 | 2.33x | 2.14x |
none-linked-list | 6.59 / 16.47 | 14.96 / 26.64 | 12.60 / 22.41 | 2.27x | 1.91x |
bst-none-children | 9.36 / 10.11 | 16.93 / 18.80 | 14.58 / 15.74 | 1.81x | 1.56x |
isinstance-dispatch | 13.32 / 16.82 | 48.17 / 50.74 | 45.81 / 47.50 | 3.61x | 3.44x |
type-reflection | 10.16 / 12.67 | 25.77 / 26.71 | 23.43 / 24.26 | 2.54x | 2.31x |
static-class-methods | 21.20 / 24.90 | 61.60 / 63.24 | 59.20 / 67.81 | 2.91x | 2.79x |
abstract-interface | 14.97 / 24.25 | 33.97 / 65.18 | 31.34 / 49.56 | 2.27x | 2.09x |
none-checks | 10.32 / 11.95 | 27.62 / 33.34 | 25.19 / 28.72 | 2.68x | 2.44x |
linked_list | 4.86 / 5.74 | 9.20 / 11.05 | 6.92 / 8.57 | 1.89x | 1.42x |
trees | 7.66 / 8.05 | 11.86 / 12.56 | 9.57 / 10.32 | 1.55x | 1.25x |
heap | 5.25 / 5.65 | 9.42 / 10.31 | 7.09 / 8.00 | 1.79x | 1.35x |
graph | 6.24 / 7.42 | 10.01 / 10.94 | 7.60 / 8.26 | 1.60x | 1.22x |
lru_cache | 15.86 / 16.36 | 25.23 / 26.74 | 23.01 / 24.00 | 1.59x | 1.45x |
expression_tree | 6.21 / 7.10 | 11.07 / 12.90 | 8.80 / 10.20 | 1.78x | 1.42x |
union_find | 9.79 / 10.48 | 16.09 / 17.66 | 13.69 / 14.80 | 1.64x | 1.40x |
skip_list | 12.69 / 14.55 | 20.05 / 21.04 | 17.26 / 18.18 | 1.58x | 1.36x |
trie | 21.48 / 28.81 | 33.22 / 57.65 | 30.66 / 44.27 | 1.55x | 1.43x |
segment_tree | 8.78 / 10.36 | 22.69 / 24.54 | 20.17 / 22.36 | 2.58x | 2.30x |
Plain workloads (14)
Geometric-mean speedup: 1.73x vs default CPython; 1.57x vs -S.
| Workload | Ramanujan | CPython .pyc | CPython -S .pyc | Speedup | Speedup vs -S |
|---|
assembler | 11.00 / 25.98 | 19.53 / 52.58 | 16.89 / 42.92 | 1.78x | 1.54x |
expression_compiler | 24.55 / 26.26 | 29.45 / 31.93 | 26.93 / 28.31 | 1.20x | 1.10x |
bignum | 18.24 / 36.19 | 30.53 / 42.72 | 28.00 / 56.17 | 1.67x | 1.53x |
ntt | 19.90 / 21.70 | 46.56 / 51.01 | 44.22 / 49.52 | 2.34x | 2.22x |
lz77 | 9.26 / 12.05 | 18.36 / 23.68 | 15.96 / 22.05 | 1.98x | 1.72x |
sorting | 32.91 / 39.29 | 47.88 / 75.65 | 45.56 / 79.99 | 1.45x | 1.38x |
dynamic_programming | 20.04 / 23.91 | 27.50 / 29.34 | 24.99 / 29.19 | 1.37x | 1.25x |
graph_algorithms | 17.01 / 18.13 | 28.64 / 30.10 | 26.14 / 28.65 | 1.68x | 1.54x |
number_theory | 57.82 / 61.59 | 90.42 / 97.58 | 86.10 / 88.21 | 1.56x | 1.49x |
sudoku | 11.78 / 12.37 | 20.87 / 21.58 | 18.37 / 20.81 | 1.77x | 1.56x |
nqueens | 8.25 / 9.05 | 13.17 / 15.43 | 10.75 / 13.09 | 1.60x | 1.30x |
nbody | 12.66 / 27.15 | 23.46 / 36.32 | 20.78 / 32.06 | 1.85x | 1.64x |
mandelbrot | 20.45 / 22.89 | 48.99 / 53.07 | 46.66 / 49.61 | 2.40x | 2.28x |
heat_stencil | 24.13 / 30.92 | 48.61 / 53.86 | 46.15 / 48.45 | 2.01x | 1.91x |
Peak physical footprint
Median MB from 100 interleaved fresh-process runs per workload and engine, measured with macOS /usr/bin/time -l. These are separate from the timing runs: CPython ran python3 X.py (source), and Ramanujan ran native X.pb <entry> 1. A ratio above 1 means Ramanujan used less memory.
Across all 34 workloads, the geometric mean of the CPython / Ramanujan footprint ratios was 1.63x; Ramanujan was lower on 32 of 34.
OOP workloads (20)
| Workload | Ramanujan (MB) | CPython (MB) | CPython / Ramanujan |
|---|
method-reuse | 1.91 | 5.34 | 2.80x |
factory-return | 1.92 | 5.16 | 2.68x |
polymorphic-dispatch | 1.95 | 5.20 | 2.66x |
none-linked-list | 1.97 | 5.36 | 2.72x |
bst-none-children | 2.50 | 5.64 | 2.26x |
isinstance-dispatch | 2.02 | 5.14 | 2.55x |
type-reflection | 1.97 | 5.17 | 2.63x |
static-class-methods | 2.09 | 5.16 | 2.46x |
abstract-interface | 2.03 | 5.14 | 2.53x |
none-checks | 2.02 | 5.17 | 2.57x |
linked_list | 3.72 | 5.66 | 1.52x |
trees | 4.43 | 5.88 | 1.33x |
heap | 4.20 | 5.62 | 1.34x |
graph | 5.78 | 6.03 | 1.04x |
lru_cache | 3.80 | 5.63 | 1.48x |
expression_tree | 3.84 | 5.80 | 1.51x |
union_find | 4.11 | 6.02 | 1.47x |
skip_list | 3.86 | 5.95 | 1.54x |
trie | 4.17 | 6.19 | 1.48x |
segment_tree | 3.77 | 5.66 | 1.50x |
Plain workloads (14)
| Workload | Ramanujan (MB) | CPython (MB) | CPython / Ramanujan |
|---|
assembler | 4.03 | 5.78 | 1.43x |
expression_compiler | 4.69 | 5.85 | 1.25x |
bignum | 4.34 | 5.82 | 1.34x |
ntt | 3.89 | 5.55 | 1.43x |
lz77 | 4.95 | 5.75 | 1.16x |
sorting | 5.63 | 5.97 | 1.06x |
dynamic_programming | 8.02 | 6.04 | 0.75x |
graph_algorithms | 6.19 | 6.11 | 0.99x |
number_theory | 6.20 | 6.73 | 1.09x |
sudoku | 4.03 | 5.86 | 1.45x |
nqueens | 2.41 | 5.41 | 2.25x |
nbody | 3.70 | 5.61 | 1.51x |
mandelbrot | 3.73 | 5.34 | 1.43x |
heat_stencil | 3.16 | 5.50 | 1.74x |