Fifteen programs written in Kairo, C++ and Rust, plus one that measures a Kairo-only feature, timed on one machine. All results are below, losses included.
One fact frames everything: Kairo compiles through Clang and LLVM. Kairo's frontend parses and type-checks the source itself, and its own Clang/LLVM 22 build is the backend. On plain arithmetic, Kairo, Clang and rustc therefore share an optimizer and a code generator, and a gap between them comes from what each frontend hands LLVM, not from the backend. Large Kairo wins come from the runtime (its mimalloc heap) or from how a language feature is lowered.
Summary: on 9 of 15 programs Kairo is within 10% of the best C++ or Rust build. It's well ahead where the heap dominates, ahead on generators, closures and the interpreter loop, and behind on nbody and, against GCC only, on virtual dispatch.
The toolchains
- kairo: the Kairo compiler at
-O3. - gcc and clang: the C++ version built by the system GCC and Clang.
- kcc: the same C++ source built by Kairo's C++ driver. It links Kairo's runtime, including the mimalloc heap that Kairo's global allocator uses. kcc is the control: when kcc closes a gap between Kairo and plain C++, the runtime caused the gap, not the language.
- rust: the Rust version built by
rustc.
Kairo is red, kcc is dimmed red, the rest are gray. Every row is labeled.
Results at a glance
Kairo against the fastest of the other four toolchains on each benchmark. Bars right of center mean Kairo is faster. The scale is logarithmic, so 2× faster and 2× slower have the same length.
- errpath 2.54× faster vs rust
- fmt 2.25× faster vs kcc
- btree 1.50× faster vs kcc
- gen 1.18× faster vs kcc
- closures 1.06× faster vs rust
- alloc 1.04× faster vs kcc-malloc
- nullable 1.04× faster vs kcc
- slices 1.00× faster vs rust
- interp 1.00× faster vs rust
- fannkuch 1.01× slower vs clang
- gsort 1.02× slower vs gcc
- wideint 1.06× slower vs gcc
- spectral 1.07× slower vs gcc
- nbody 1.60× slower vs rust
- dispatch 2.50× slower vs gcc
Kairo has the fastest median on 9 of 15 and loses 6. Nine of the 15 are within 10% either way; with eight runs, treat those as ties.
Each per-benchmark chart shows the median of eight runs as a bar and the fastest run as a tick. The right column is speed relative to Clang. Hover or focus a row for exact numbers.
Numeric loops
No allocation. These measure the code each frontend gives LLVM (or GCC) for arithmetic and array loops.
- rust 0.785s 1.88×
- gcc 1.180s 1.25×
- kairo 1.254s 1.18×
- kcc 1.365s 1.08×
- clang 1.478s base
nbody: five bodies, 30 million steps, f64 math over a fixed array of structs. Rust is 1.88× faster than Clang. Kairo is 1.18× faster than Clang and 6% slower than GCC.
- clang 1.590s base
- kairo 1.602s 0.99×
- kcc 1.617s 0.98×
- rust 1.694s 0.94×
- gcc 1.768s 0.90×
fannkuch: permutations and prefix reversals over a 16-element integer array. All five are within 11%; Clang leads Kairo by under 1%. One Kairo run took 1.189 s, 26% under its median. Every other toolchain's fastest run is within 1% of its median. The median is the number.
- gcc 1.053s 1.06×
- clang 1.117s base
- kcc 1.122s 1.00×
- kairo 1.125s 0.99×
- rust 1.125s 0.99×
- gcc 0.922s 1.01×
- rust 0.926s 1.01×
- clang 0.934s base
- kcc 0.970s 0.96×
- kairo 0.980s 0.95×
- kairo 1.265s 1.01×
- rust 1.271s 1.00×
- kcc 1.271s 1.00×
- clang 1.273s base
- gcc 1.298s 0.98×
spectral (spectral norm, f64), wideint (64-bit Miller–Rabin with a 128-bit multiply-mod) and slices (sum, dot product and filter over a million f64s) are ties. The spreads are 7%, 6% and 3%. This is the expected result when three frontends hand LLVM equivalent loops.
Memory
The kcc column matters most here.
- kairo 2.230s 2.67×
- kcc 3.342s 1.78×
- gcc 5.323s 1.12×
- clang 5.965s base
- rust 6.200s 0.96×
kcc builds the same C++ as gcc and clang but links Kairo's runtime heap. That alone takes it from 5.3 s to 3.3 s.
btree builds and frees millions of small binary trees, one heap allocation per node. Kairo is 2.7× faster than Clang, and most of that is the allocator. @create goes to the global allocator, which is mimalloc's small-object path; the GCC, Clang and Rust builds use glibc malloc.
kcc separates the two effects. The same C++ linked against Kairo's runtime drops from 5.3 s to 3.3 s, so most of the gap is the heap. Kairo is still 1.5× faster than kcc. Part of that is the free path: Kairo frees with the size and alignment it already knows (destroy calls mimalloc's sized small-object free directly, 3 instructions on the hot path), while C++ delete goes through operator delete to an unsized free, which has to look up the block's page first.
- kairo 0.121s 1.66×
- kcc-malloc 0.126s 1.60×
- kcc-new 0.135s 1.49×
- clang-malloc 0.201s base
- gcc-malloc 0.202s 1.00×
- rust 0.256s 0.79×
- gcc-new 0.269s 0.75×
- clang-new 0.272s 0.74×
alloc creates and destroys one 16-byte object 50 million times; the C++ is built once with new/delete and once with malloc/free. It's the cleanest allocator comparison in the set. Kairo and kcc-malloc are within 4% of each other and 1.6× faster than glibc malloc. A Kairo create/destroy pair is 49 instructions, against 146 for glibc malloc/free and 157 for new/delete. Through glibc, new/delete costs a third more than malloc/free; through Kairo's runtime, 7% more.
- kairo 0.542s 1.55×
- kcc 0.563s 1.49×
- rust 0.814s 1.03×
- gcc 0.820s 1.02×
- clang 0.840s base
nullable builds a 10-million-node linked list with nullable next links, walks and searches it 50 times, then frees it. kcc is within 4% of Kairo, and both are 1.5× ahead of the rest, so most of this one is the heap.
The remaining few percent is the free path, as in btree. Kairo's @destroy frees each node with the size and alignment it already knows, through the runtime's sized free. The C++ list is a chain of std::unique_ptr: in kcc's build, unique_ptr::reset stays an out-of-line call (seven call sites in main), and each node goes through operator delete to an unsized free.
Abstractions
Stored closures, virtual calls, generators, generic code, and an interpreter loop over match.
- kairo 0.735s 3.36×
- rust 0.777s 3.17×
- clang 2.466s base
- kcc 2.656s 0.93×
- gcc 5.370s 0.46×
closures calls three capturing callbacks stored in an array, a billion times. All three languages use a type-erased callable: Kairo's fn values, Rust's Box<dyn Fn>, and std::function in C++, which is what C++ uses when a callback has to be stored. Kairo is 6% faster than Rust; std::function is 3.4× slower with Clang and 7.3× slower with GCC. A C++ template that takes the lambda directly would inline, but then the callback isn't stored.
- gcc 0.813s 2.50×
- kairo 2.029s 1.00×
- rust 2.030s 1.00×
- clang 2.030s base
- kcc 2.316s 0.88×
dispatch makes virtual calls over a mixed array of 1,024 shapes. GCC is 2.5× faster than Kairo, Clang and Rust, which all finish in 2.03 s. Kairo matching Clang here is expected, since Kairo classes share the C++ vtable ABI and their virtual calls go through the same backend as Clang's. GCC is the outlier because of speculative devirtualization: the derived classes are final, so GCC knows the complete set of three overriders and can replace the indirect call with type checks and inlined bodies.
- kairo 0.560s 1.20×
- kcc 0.661s 1.01×
- clang 0.670s base
- rust 0.931s 0.72×
- gcc 3.698s 0.18×
gen is a three-stage pipeline of nested generators summing a billion values: -> yield T in Kairo, C++20 coroutines in C++, iterator adapters in Rust. Kairo generators are built on the same coroutine machinery as C++20 coroutines, so Kairo and the Clang row share it. In both, Clang elides the coroutine frames' heap allocations and inlines the whole pipeline into the caller's loop. GCC doesn't perform that elision, which is why its row is 6.6× slower. Kairo is 1.2× ahead of Clang and 1.7× ahead of Rust. The difference between Kairo and Clang is Kairo's promise type and how yield is lowered. Like fannkuch, gen has one outlier run (0.451 s, 20% under the median).
- gcc 1.005s 1.02×
- kairo 1.027s 1.00×
- clang 1.028s base
- kcc 1.030s 1.00×
- rust 1.035s 0.99×
- rust 0.338s 2.94×
- kcc 0.967s 1.03×
- gcc 0.986s 1.01×
- clang 0.995s base
Reference only: each language's library sort. Kairo's standard library has no sort yet, so it has no row.
gsort is a hand-written generic sort over a comparison bound, with closures for the key. All five are within 3%: Kairo generics are monomorphized like C++ templates and Rust generics, so an interface bound adds nothing at runtime. gsort-lib swaps in each library's sort for reference. Rust's sort_unstable (pattern-defeating quicksort) is 2.9× faster than libstdc++'s std::sort (introsort), and that's the target for Kairo's.
- kairo 1.100s 1.36×
- rust 1.102s 1.35×
- gcc 1.375s 1.09×
- clang 1.493s base
- kcc 1.529s 0.98×
interp runs a small bytecode loop: an enum with payloads and match in Kairo and Rust, a tagged struct and switch in C++. Kairo and Rust tie, and both are at least 1.25× faster than every C++ build. Since Kairo and the Clang row share a backend, the difference is in the representation Kairo chooses for its enum and match, not in code generation.
Errors and formatting
Kairo's two largest wins.
- kairo 0.222s 10.19×
- rust 0.564s 4.01×
- clang 2.262s base
- gcc 2.341s 0.97×
- kcc 8.209s 0.28×
errpath makes 500 million calls, 1% of which fail: panic/try/catch in Kairo, exceptions in C++, Result in Rust. Kairo is 10× faster than C++ exceptions and 2.5× faster than Rust's Result.
A Kairo panic is a returned value, not an unwind, so LLVM treats the failure path like any other branch. In the Kairo build parse and fail are inlined into the loop, x % 100 == 0 becomes a multiply-and-rotate test, x * 3 becomes a running += 3, and no error value is ever built. Rust's Result gets the same treatment, so the gap to Rust is loop shape, not error handling. Rust's 1..=n adds an exhaustion check to every iteration, and LLVM computes both outcomes and picks one with cmov instead of branching: 18 instructions per iteration against Kairo's 13 on the success path, and Kairo's branch is predicted right 99% of the time. The C++ builds pay for 5 million throws, each one allocating the exception (__cxa_allocate_exception) and unwinding to the catch.
The kcc row is a bug in kcc's link, not a cost of exceptions: the same code is 3.5× slower than GCC's build.
- kairo 0.110s 2.96×
- kcc 0.247s 1.32×
- clang 0.326s base
- gcc 0.336s 0.97×
- rust 0.589s 0.55×
fmt converts 10 million f64s and 10 million i64s to text: f-strings in Kairo, std::to_chars in C++, write! in Rust. Kairo is 2.2× faster than kcc and 3.0× faster than Clang. Kairo's f-strings format into a buffer with 128 bytes of inline storage, so short results never touch the heap, and floats with no format spec are written directly into that buffer.
Scoped allocators (Kairo only)
scopes has no C++ or Rust version; it measures Kairo's scoped allocator stack. It opens DEPTH nested allocator scopes, then runs 50 million operations at the innermost level. Times per operation:
| Operation | depth 1 | depth 16 | depth 64 |
|---|---|---|---|
| allocate + free in the innermost scope | 2.5 ns | 2.5 ns | 2.7 ns |
| free a global block inside the scopes | 3.1 ns | 3.1 ns | 3.1 ns |
| free a block from the outermost scope | 1.4 ns | 7.2 ns | 21.6 ns |
| open and close one more scope | 6.2 ns | 6.6 ns | 6.6 ns |
free has to find which open scope, if any, owns an address. The scope stack keeps a bounding box over every open scope's memory, so an address outside it (a global block) is rejected with one range check, at any depth. An address inside the box is found by scanning the open scopes from innermost outward, so freeing a block that belongs to the outermost scope costs 0.3 to 0.4 ns for every scope above it: a few nanoseconds at realistic depths, 22 ns at 64.
Method
The code is in Tests/bench. Each program is written the way that language's code is normally written; the README lists what each version uses (std::function vs Box<dyn Fn>, exceptions vs Result, and so on). None is tuned for a particular compiler.
- Builds:
-O3for Kairo, GCC, Clang and kcc (-std=c++20for C++);-C opt-level=3 -C codegen-units=1for Rust. No-march=native, LTO or PGO. - Timing:
bench-seq.fish 8builds and times one benchmark at a time. Toolchains are interleaved within a benchmark (each binary once, then each again) for eight rounds, so a background-load swing hits all of them. - Measured: wall-clock time of the whole process, startup and output included.
- Correctness: each benchmark prints a checksum; the harness checks every toolchain prints the same one. All sixteen agreed.
- Machine: AMD Ryzen 9 7900X (12 cores / 24 threads), Linux 7.2.11-zen1, GCC 16.2.1, Clang 23.1.3, rustc 1.98.1, Kairo at commit
f66b5057(Clang/LLVM 22 backend).
Limits
- Eight runs. Most medians are within 1 to 2% of the fastest run (Kairo's fannkuch and gen are the exceptions). Don't rank differences under 5%.
- Each language uses its default allocator and standard library. That's why btree, alloc and nullable look the way they do, and why kcc is in the table.
- Some Kairo sources work around open compiler bugs:
gsort.kwrapsi64in aKeystruct,gen.kyields only named variables, andspectral.kavoids one parameter name. The README lists them. - Single-threaded micro-benchmarks. No threads, I/O, or large programs.
If you run the suite on other hardware, especially ARM, send me the results.