Benchmarks

Benchmark results

The Typhon repository contains a suite of small benchmark programs. Each program is a single file that is valid Python and valid Typhon, so CPython and Typhon run the same source. This page summarises the published results. They come from one machine and from programs of 10 to 85 lines of code. Larger applications have not been measured.

Method and limits

  • Each program times its own hot section with time.perf_counter(). Data setup and compilation are excluded, except in the section on one-off scripts.
  • Every configuration ran five times, and the median is reported.
  • Runs on this machine vary by roughly 10 to 30 percent. Windows and Linux figures can be compared only within one table.
  • Every tool printed the same result as CPython for every program, on Windows and on Linux.
  • NumPy programs ran with default threads and single-threaded, on both sides, and each side is shown in its faster setting. With default threads, OpenBLAS needed 1,024 ms for the 300 x 300 linear algebra program and 31.7 ms single-threaded. This slowdown is a known over-subscription problem on CPUs with performance and efficiency cores.
  • PyPy, Cython, mypyc, Numba and CPython's experimental JIT were not measured.
MachineIntel Core Ultra 9 285HX laptop (8 performance and 16 efficiency cores, 64 GB RAM)
Windows.NET SDK 11.0.100, CPython 3.15.2, NumPy 2.5.5 with OpenBLAS 0.3.34
LinuxUbuntu 26.04 on WSL2 on the same machine; Codon 0.20.7 and Pythran 0.19.0

Typed pure-Python programs

Typhon turns annotated Python into statically typed code. A float attribute becomes an unboxed double field, and a call becomes a direct call, while CPython executes bytecode on boxed objects. The gap is widest for arithmetic on simple types and narrowest where CPython already spends its time in C, as in hashing, string comparison and sorting. Over the nine programs, the geometric mean speed-up is 11.1x with the JIT and 13.6x with Native AOT.

Speed-up over CPython, typed pure-Python programs Windows, plugged in. Logarithmic axis; 1x is CPython's speed.
  • Typhon JIT
  • Typhon Native AOT
N-body
Spectral norm
Mandelbrot
fib(32)
Binary trees
Fannkuch
Prime sieve
Word count
sorted()

Native AOT is faster than the JIT on six of the nine programs and level on Mandelbrot. The JIT is faster on N-body and sorted(). The benchmark report gives the JIT's profile-guided optimisation at run time as the reason.

ProgramCPythonTyphon JIT Typhon AOTSpeed-up JITSpeed-up AOT RAM CPythonRAM JITRAM AOT
N-bodyfloat math on object attributes3,024 ms 40.3 ms43.8 ms 75x69x 12 MB21 MB9 MB
Spectral normnested loops, small function calls469 ms 9.7 ms8.6 ms 48x54x 12 MB21 MB9 MB
Mandelbrottight float loop2,067 ms 51.1 ms51.9 ms 40x40x 12 MB20 MB9 MB
fib(32)recursive calls134 ms 9.0 ms4.7 ms 15x29x 12 MB20 MB9 MB
Binary treesmillions of small objects783 ms 75.3 ms55.5 ms 10x14x 22 MB43 MB32 MB
Fannkuchint lists, swaps, slicing324 ms 39.1 ms28.4 ms 8.3x11x 12 MB41 MB27 MB
Prime sievelist indexing, sum over a generator989 ms 358 ms199 ms 2.8x5.0x 50 MB37 MB23 MB
Word countstring building, dict updates413 ms 161 ms140 ms 2.6x3.0x 12 MB41 MB27 MB
sorted()sorting 1M ints and 300k strings353 ms 182 ms218 ms 1.9x1.6x 88 MB61 MB54 MB

Before whole-program type inference existed, the N-body source without annotations fell back to dynamic and ran 1.5x faster than CPython. With inference, it runs as fast as the annotated version: 74x and 72x in the same run on battery.

NumPy programs

Typhon does not compile NumPy, whose core is C and Fortran. It runs these programs against Typhon.NumPy, a NumPy-compatible library written in C# for the project. Over the six programs, the result is close to parity: a geometric mean of 1.04x with the JIT and 1.13x with Native AOT. Typhon.NumPy is faster where NumPy pays a per-call overhead in Python. In these runs, NumPy was faster where it calls OpenBLAS and LAPACK.

The matrix multiplication and linear algebra rows predate a rewrite of Typhon.NumPy's dense linear algebra. On Linux with an Intel Core i7-10700K, a 1000 x 1000 matrix product then ran at 74 to 86 % of OpenBLAS's speed on one thread and about as fast on all cores, and inv of a 1000 x 1000 matrix went from 1.5 s to 91 ms, against 63 ms for NumPy. Section 9 of the benchmark report has the details.

Speed of Typhon relative to NumPy Windows, each side in its faster thread setting. Logarithmic axis; right of 1x, Typhon is faster.
  • Typhon JIT
  • Typhon Native AOT
Element loop a[i]
Broadcasting
ufuncs
Reductions
Matmul 1000 x 1000
linalg 300 x 300
ProgramNumPyTyphon JITTyphon AOT Result, fastest Typhon buildRAM NumPyRAM JIT RAM AOT
Element loop a[i]271 ms54.0 ms n/a (dynamic)Typhon 5.0x faster 43 MB61 MB n/a
Broadcasting268 ms95.9 ms 52.9 msTyphon 5.1x faster 211 MB516 MB 578 MB
ufuncs1,184 ms1,089 ms 522 msTyphon 2.3x faster 74 MB362 MB 225 MB
Reductions414 ms340 ms 224 msTyphon 1.8x faster 89 MB91 MB 72 MB
Matmul 1000 x 100017.4 ms24.4 ms 40.3 msNumPy 1.4x faster 64 MB89 MB 56 MB
linalg 300 x 30031.7 ms325 ms 159 msNumPy 5.0x faster 37 MB37 MB 16 MB

Start-up and footprint

The start-up program splits, uppercases and joins a string, and the times run from process start to exit. As a Native AOT executable, the Typhon program was the fastest and leanest of all tools tested on Linux.

ToolWindows timeWindows RAM Linux timeLinux RAMWhat is shipped
CPython 19.7 ms 12 MB 9.2 ms12 MBthe .py file and a Python installation
Codon n/a n/a 8.3 ms10 MBa small executable and Codon's runtime libraries
Typhon JIT 34.5 ms 20 MB 20 ms30 MBa 0.05 MB .dll and the .NET runtime
Typhon Native AOT 21.3 ms 9 MB 1.8 ms4 MBone self-contained 1.5 to 1.9 MB executable

Codon runs on Linux and macOS, so it has no Windows figures.

One-off scripts, compile time included

A script often runs only once, so this comparison times the whole process: python script.py against typhon run script.ty in its three situations, and against programs built ahead of time. The first typhon run compiles in its own process. Later runs use the warm compile server, and an unchanged script comes from the cache. All times are in milliseconds and were measured on Windows on battery.

ProgramCPythonFirst run Compile serverCachedtyphon build Built, per runbuild --aotAOT, per run
Tiny script (start-up)30.0642 84.080.01,034 45.05,77523.0
fib(32)155654 88.083.01,026 72.05,91734.0
Spectral norm536671 107111939 58.05,88741.0
Word count428935 400281996 2216,736228
Binary trees948719 204174955 1286,61099.0
Prime sieve1,4491,102 431431923 4256,083251
Mandelbrot2,063691 167147954 1165,61393.0
N-body3,283721 146126915 95.05,54678.0
N-body without type hints3,301670 165114947 1035,85280.0
NumPy matmul169667 1671401,128 1216,19988.0
NumPy ufuncs1,6662,080 1,7031,632952 1,5256,151710

In this table, the first run is already faster than CPython for five programs, for example N-body with 721 ms against 3,283 ms. With the compile server or the cache, CPython stays faster only for the tiny script and is level on the two NumPy programs whose time goes into BLAS and ufunc kernels. typhon build takes about one second, and every built pure-Python benchmark except the tiny start-up script makes up for it after 1 to 13 runs. Native AOT builds take 5.5 to 6.7 seconds.

Plain loops against vectorized NumPy

The same problems written as plain Python loops and as vectorized NumPy code, each run on both runtimes on Windows. With the JIT, plain loops in Typhon run 6 to 38 times faster than the same loops in CPython. They beat vectorized NumPy on three of the six problems, where vectorizing forces extra work: Mandelbrot cannot stop early per point, and pairwise distances and π build large temporary arrays. NumPy stays ahead where one tuned kernel does the whole job, as BLAS does for the dot product and matrix multiplication.

ProblemCPython loopsCPython + NumPy Typhon loops, JITTyphon loops, AOT Typhon + NumPy, AOT
Mandelbrot 400 x 400496 ms415 ms 14.2 ms11.4 ms 234 ms
Pairwise distances, 1500 points148 ms30.3 ms 3.9 ms3.3 ms 8.1 ms
Estimate π, 5M points388 ms160 ms 45.0 ms43.5 ms 32.9 ms
Moving average, 5M samples329 ms31.3 ms 56.0 ms56.3 ms n/a (dynamic)
Dot product, 10M floats152 ms1.4 ms 6.8 ms6.5 ms n/a (dynamic)
Matrix multiply 200 x 200206 ms0.4 ms 12.3 ms7.4 ms 0.7 ms

Other Python compilers on Linux

The same files were compiled with Codon, which compiles whole programs to native code through LLVM, and with Pythran, which compiles numeric functions to C++. Each tool is compared with CPython on Linux. On the six programs that all four can compile, the geometric means are 13.6x for Pythran, 11.8x for Typhon AOT, 11.6x for Codon and 9.2x for the Typhon JIT. Typhon is at or near the top on float- and object-heavy code. Codon and Pythran lead on integer and list code and on NumPy-style code.

ProgramCodonPythranTyphon JIT Typhon AOT
N-body37xn/a (classes) 62x54x
Spectral norm39x39x 41x28x
Mandelbrot16x26x 28x28x
fib(32)14x25x 14x28x
Binary treesn/a (string annotation)n/a (classes) 8.2x13x
Fannkuch9.5x15x 6.6x9.3x
Prime sieve12x15x 2.8x5.1x
sorted()3.9xn/a (not in a function) 2.0x1.6x
Word count2.5x1.2x 1.9x2.6x
N-body without type hints29xn/a (classes) 1.1 (before inference)n/a (dynamic)
NumPy element loop19x31x 4.4xn/a (dynamic)
NumPy broadcasting1.1x5.1x 1.4x2.4x
NumPy ufuncs1.5x2.3x 0.8x1.9x
NumPy matmul 1000 x 10000.4xn/a (not in a function) 0.6x0.3x

The Linux run predates whole-program type inference, so Typhon falls back to dynamic on N-body without type hints and reaches 1.1x. Codon infers types for the whole program and reaches 29x on the same source. A new Linux run with inference is one of the roadmap ideas.

Memory

With the JIT, a Typhon process starts about 8 MB higher than CPython because of the .NET runtime. Native AOT removes that floor, with 9 MB against CPython's 12 MB on Windows. Typhon's garbage collector frees memory in batches, so allocation-heavy programs use more RAM with the JIT and with Native AOT. Typed lists are much denser than Python lists, so programs that hold large lists use less memory, for example 175 MB against 468 MB for the dot product. Large temporary NumPy arrays are Typhon's weak spot, with up to five times NumPy's peak.

Sources

All figures on this page come from the Typhon repository at commit 106cf11. The report also explains each measurement and compares the plugged-in run with the run on battery power.