3 programs measured with axle bench: arena_micro, gather_sweep, shared_rc_micro. Run time, peak RAM at compile and run, and binary size, with the exact source for each language.
Benchmarks for v0.23.0
Arena-allocation micro-benchmark — millions of short-lived objects, all three languages performing a real per-iteration allocation (C++/Rust forced past inlining, Axle routed onto its real arena allocator).
| Variant | Run | Compile | Output | ||
|---|---|---|---|---|---|
| Run time | RAM | Compile time | RAM | Binary | |
| Axle -O1 | 18 ms | 45.4 MB | 80 ms | 125.4 MB | 318 KB |
| Axle -O2 | 19 ms | 45.4 MB | 84 ms | 123.0 MB | 318 KB |
| Axle -O3 | 19 ms | 45.4 MB | 86 ms | 123.4 MB | 318 KB |
| Axle -O0 | 33 ms | 45.4 MB | 73 ms | 123.5 MB | 319 KB |
| Rust -O2 | 53 ms | 45.4 MB | 111 ms | 142.7 MB | 3865 KB |
| Rust -O3 | 53 ms | 45.4 MB | 111 ms | 138.8 MB | 3865 KB |
| Rust -O1 | 55 ms | 45.4 MB | 109 ms | 142.6 MB | 3866 KB |
| C++ -O1 | 59 ms | 45.4 MB | 88 ms | 95.7 MB | 16 KB |
| C++ -O2 | 59 ms | 45.4 MB | 89 ms | 95.9 MB | 16 KB |
| C++ -O3 | 59 ms | 45.4 MB | 89 ms | 95.9 MB | 16 KB |
| C++ -O0 | 71 ms | 45.4 MB | 85 ms | 91.5 MB | 16 KB |
| Rust -O0 | 156 ms | 45.4 MB | 89 ms | 143.0 MB | 3877 KB |
// EXPECTED_EXIT: 0
// Arena-allocation microbench — a REAL per-iteration allocation the
// optimiser cannot elide, so it measures the allocator, not dead-code
// removal.
//
// Each iteration allocates a fresh `Node` and publishes it to `prev`, an
// outer-scope local the NEXT iteration reads back through `prev.value`.
// That cross-iteration alias is the whole point: a stack slot would be
// reused across iterations (every `new Node` re-initialising the one slot
// `prev` aliases), so sema cannot stack-promote it — the escape pass keeps
// it heap-resident and the arena pass, proving it never leaves the frame,
// routes it to the **arena** tier (`arena Node(...)`, a bump-pointer
// allocation). C++ and Rust cannot elide their siblings for the same
// reason: each object's address is observed a step later, so a genuine
// `new` / `Box::new` fires every iteration.
//
// This is the allocator comparison the arena tier exists for: Axle bumps a
// thread-local cursor (no per-object free — the whole run is reclaimed by
// the function's scope-exit rewind), against C++/Rust paying `new`/`delete`
// per iteration. `run` marks the arena once on entry and rewinds once on
// return, so the hot loop is 5M bumps.
use std::sys::process::argc;
class Node {
pub(file) value : i64;
constructor(v : i64) {
self.value = v;
}
}
// Per-iteration allocation, aliased one step forward so the object is a
// real (non-elidable) allocation the arena serves by bumping.
fn run(n : i64) : i64 {
let mut prev : Node = new Node(0);
let mut acc : i64 = 0;
let mut i : i64 = 1;
let mut state : i64 = 88172645463325252;
while (i <= n) {
state = state * 6364136223846793005 + 1442695040888963407;
let cur : Node = new Node(state);
acc = acc + prev.value;
prev = cur;
i = i + 1;
}
return acc;
}
fn main() : i32 {
let n : i64 = 5000000 + (argc() as i64);
println(run(n));
return 0;
}One scattered read swept across the whole cache hierarchy — five working sets from 64 B to 64 MiB, reported as picoseconds per gathered element. The point is the shape of the two curves rather than either endpoint: inside L1 the loop is bound by the dependent index -> load -> accumulate chain, past L3 by memory latency, and whether Axle pays more than C++ for the second is a question about how they diverge.
| Variant | Run | Compile | Output | ||
|---|---|---|---|---|---|
| Run time | RAM | Compile time | RAM | Binary | |
| C++ -O2 | 303 ms | 66.7 MB | 534 ms | 123.9 MB | 16 KB |
| C++ -O3 | 303 ms | 66.7 MB | 551 ms | 123.6 MB | 16 KB |
| Axle -O2 | 304 ms | 65.5 MB | 96 ms | 127.1 MB | 308 KB |
| Axle -O3 | 304 ms | 65.5 MB | 96 ms | 126.0 MB | 308 KB |
| Rust -O3 | 308 ms | 65.9 MB | 126 ms | 149.7 MB | 3873 KB |
| C++ -O1 | 313 ms | 66.7 MB | 529 ms | 122.7 MB | 16 KB |
| Rust -O2 | 313 ms | 65.9 MB | 127 ms | 147.9 MB | 3873 KB |
| Axle -O1 | 344 ms | 65.5 MB | 86 ms | 125.9 MB | 308 KB |
| Rust -O1 | 360 ms | 65.9 MB | 118 ms | 149.7 MB | 3873 KB |
| Axle -O0 | 576 ms | 65.5 MB | 79 ms | 126.1 MB | 308 KB |
| C++ -O0 | 785 ms | 66.7 MB | 522 ms | 117.3 MB | 17 KB |
// EXPECTED_EXIT: 0
// Gather sweep — the same scattered read, over a table swept across the
// cache hierarchy. Shared logic with gather_sweep.cpp / gather_sweep.rs
// (run via `axle bench --compare cpp,rust`).
//
// # What it measures, and why a sweep
//
// A cache question cannot be answered at one working-set size. The point is
// the *shape of the curve*: a gather over a table that fits L1 is bounded by
// the dependent chain `index -> load -> accumulate`, and the same gather over
// a table past L3 is bounded by memory latency instead. Whether this language
// pays more than C++ for the second is a question about how the two curves
// diverge, not about either endpoint.
//
// So one kernel runs at five sizes — 64 B, 16 KiB, 256 KiB, 4 MiB, 64 MiB —
// landing inside L1, inside L2, around L3, and well past it on a typical
// desktop part. Each is timed on its own and reported as **picoseconds per
// element**; the iteration count is held fixed across sizes, so a rising
// number is the memory system and nothing else.
//
// # Why the reads cannot be elided or predicted
//
// Each index comes from an xorshift step over the previous one, so the address
// of a read depends on arithmetic the hardware prefetcher cannot run ahead of
// — that is what makes this a *gather* rather than a stride. The accumulator
// reaches the output, so no read is dead, and the table is filled from its own
// index, so no load folds to a constant.
//
// # Why these five sizes
//
// They are the sweep behind `axle_common::limits::RANDOM_ACCESS_UNROLL_FACTOR`,
// deliberately: that constant's measurement is the only prior reading of this
// hierarchy in the tree, and a second instrument choosing other points could
// not be compared against it.
use std::sys::process::argc;
use std::sys::nanoTime;
// Element counts, 8 bytes each: 64 B, 16 KiB, 256 KiB, 4 MiB, 64 MiB.
const SIZE_L1 : i64 = 8;
const SIZE_L2 : i64 = 2048;
const SIZE_L3 : i64 = 32768;
const SIZE_BIG : i64 = 524288;
const SIZE_RAM : i64 = 8388608;
// Held fixed across every size, so picoseconds/element compare directly.
const ITERS : i64 = 20000000;
// Time one working-set size and report picoseconds per gathered element.
//
// Allocation, fill, gather and release all happen here: a heap buffer whose
// count is dynamic is a pointer, and handing it across a call would say
// nothing this loop does not already say.
fn measure(len : i64, seed : i64) : i64 {
let mut table : i64[] = new i64[len];
let mut i : i64 = 0;
while (i < len) {
table[i] = i * 2654435761 + 1;
i = i + 1;
}
// `len` is a power of two, so the index wraps with an `and` rather than a
// division — the loop measures the memory system, not the modulo.
let mask : i64 = len - 1;
let mut acc : i64 = 0;
let mut state : i64 = seed;
let start : i64 = nanoTime();
let mut k : i64 = 0;
while (k < ITERS) {
// `>>>`: the xorshift is specified over an unsigned word.
state = state ^ (state << 13);
state = state ^ (state >>> 7);
state = state ^ (state << 17);
acc = acc + table[state & mask];
k = k + 1;
}
let elapsed : i64 = nanoTime() - start;
drop table;
// Picoseconds per gathered element. `acc` is *not* folded in here: an
// expression a constant-fold can prove is zero (`acc & 0`) takes the whole
// accumulation with it, and the first draft of this file measured five
// eliminated loops. It is returned instead, and printed by the caller.
println(elapsed * 1000 / ITERS);
return acc;
}
fn main() : i32 {
// `argc()` is opaque to the optimiser, so the seed is not a constant and
// the sweep cannot be evaluated at compile time.
let seed : i64 = 88172645463325252 + (argc() as i64);
let mut sink : i64 = 0;
// Ascending working-set order: the curve reads top to bottom.
sink = sink + measure(SIZE_L1, seed);
sink = sink + measure(SIZE_L2, seed);
sink = sink + measure(SIZE_L3, seed);
sink = sink + measure(SIZE_BIG, seed);
sink = sink + measure(SIZE_RAM, seed);
// The accumulators reach the output, which is what keeps five gather loops
// alive. Printed after the curve so the five timings read as a block.
println(sink);
return 0;
}Thread-locality feature bench — Axle's Shared<T> proven never to cross a spawn drops to a non-atomic refcount, compared against Rust's non-atomic Rc<T> (the fair baseline) and the always-atomic Arc<T> / std::shared_ptr<T>.
| Variant | Run | Compile | Output | ||
|---|---|---|---|---|---|
| Run time | RAM | Compile time | RAM | Binary | |
| Axle -O1 | 41 ms | 45.3 MB | 75 ms | 121.4 MB | 317 KB |
| Axle -O2 | 41 ms | 45.3 MB | 81 ms | 123.5 MB | 317 KB |
| Axle -O3 | 41 ms | 45.3 MB | 81 ms | 123.3 MB | 317 KB |
| C++ -O3 | 59 ms | 45.3 MB | 95 ms | 96.5 MB | 16 KB |
| C++ -O1 | 60 ms | 45.3 MB | 94 ms | 95.9 MB | 16 KB |
| C++ -O2 | 61 ms | 45.3 MB | 95 ms | 96.5 MB | 16 KB |
| Rust -O1 | 64 ms | 45.3 MB | 115 ms | 146.8 MB | 3866 KB |
| Rust -O3 | 64 ms | 45.3 MB | 116 ms | 149.2 MB | 3866 KB |
| Rust -O2 | 69 ms | 45.3 MB | 116 ms | 149.0 MB | 3866 KB |
| Axle -O0 | 112 ms | 45.3 MB | 72 ms | 125.0 MB | 317 KB |
| C++ -O0 | 134 ms | 45.3 MB | 86 ms | 91.4 MB | 16 KB |
| Rust -O0 | 260 ms | 45.3 MB | 95 ms | 147.7 MB | 3878 KB |
// EXPECTED_EXIT: 0
// Shared<Node> refcount microbench — a REAL per-iteration retain/release
// the optimiser cannot elide, so it measures the refcount + allocator,
// not dead-code removal.
//
// Each iteration allocates a fresh `shared Node`, aliases it once
// (a retain — strong 1→2), reads both the alias and the outer-scope
// `prev` handle the PREVIOUS iteration published, then hands the new node
// to `prev`. That reassignment releases the previous node (its last strong
// drop → free) and the intra-iteration alias drops at scope exit (a second
// release). The cross-iteration `prev` is the whole point: the handle
// escapes the loop body — a step later its value is still observed — so
// sema cannot stack-promote the node and elide its refcount, exactly as
// the C++ / Rust siblings cannot elide `new`/`Rc::new` whose address is
// observed a step later.
//
// `Node`'s `Shared<Node>` never crosses a `spawn`, so
// `axle_sema::hir_analyses::thread_locality` proves the class thread-local:
// every retain / release lowers to a plain load/add-or-sub/store instead of
// an `atomicrmw`, and the last-strong drop skips the `fence(Acquire)`
// The C++ sibling
// hand-rolls a non-atomic intrusive count and Rust uses `Rc<T>`, its own
// non-atomic shared pointer, so all three measure the identical thing:
// non-atomic retain/release churn under a genuine per-step allocation.
use std::sys::process::argc;
class Node {
pub(file) value : i64;
constructor(v : i64) {
self.value = v;
}
}
// Per-iteration alloc + retain + release, with the node aliased one step
// forward through `prev` so it is a real (non-elidable) shared allocation.
fn run(n : i64) : i64 {
let mut prev = share new Node(0);
let mut acc : i64 = 0;
let mut i : i64 = 1;
let mut state : i64 = 88172645463325252;
while (i <= n) {
state = state * 6364136223846793005 + 1442695040888963407;
let cur = share new Node(state);
let alias = cur;
acc = acc + prev.value + alias.value;
prev = cur;
i = i + 1;
}
return acc;
}
fn main() : i32 {
let n : i64 = 5000000 + (argc() as i64);
println(run(n));
return 0;
}