4 programs measured with axle bench: bits_intensive, licm_hoist, mandelbrot, math_intensive. Run time, peak RAM at compile and run, and binary size, with the exact source for each language.
Benchmarks for v0.23.0
Bit-twiddling throughput — popcount / clz / ctz / bswap / rotate / bitreverse, all three languages routed through the matching native intrinsic.
| Variant | Run | Compile | Output | ||
|---|---|---|---|---|---|
| Run time | RAM | Compile time | RAM | Binary | |
| Axle -O3 | 12 ms | 46.1 MB | 77 ms | 123.1 MB | 303 KB |
| Rust -O2 | 12 ms | 46.1 MB | 91 ms | 141.2 MB | 3862 KB |
| Axle -O1 | 13 ms | 46.1 MB | 74 ms | 124.8 MB | 303 KB |
| Axle -O2 | 13 ms | 46.1 MB | 76 ms | 124.8 MB | 303 KB |
| Rust -O1 | 13 ms | 46.1 MB | 93 ms | 137.6 MB | 3862 KB |
| Rust -O3 | 13 ms | 46.1 MB | 91 ms | 139.3 MB | 3862 KB |
| Axle -O0 | 39 ms | 46.1 MB | 71 ms | 123.3 MB | 303 KB |
| C++ -O2 | 45 ms | 46.1 MB | 96 ms | 96.5 MB | 16 KB |
| C++ -O3 | 45 ms | 46.1 MB | 94 ms | 96.6 MB | 16 KB |
| Rust -O0 | 47 ms | 46.1 MB | 85 ms | 139.1 MB | 3865 KB |
| C++ -O1 | 161 ms | 46.1 MB | 91 ms | 95.5 MB | 16 KB |
| C++ -O0 | 581 ms | 46.1 MB | 85 ms | 90.6 MB | 16 KB |
// Bit-twiddling stress test — hammers six `std::core::bits` fns:
// popcount64 / leadingZeros64 / trailingZeros64 / byteSwap64 /
// rotateLeft64 / bitReverse64.
//
// All six route through a compiler intrinsic (`popcnt_i64` /
// `ctlz_i64` / `cttz_i64` / `bswap_i64` / `rotl_i64` /
// `bitreverse_i64` — see `crates/5-stdlib/axle_stdlib/axle/core/bits.axle`),
// each lowering to the single-instruction `@llvm.ctpop` /
// `@llvm.ctlz` / `@llvm.cttz` / `@llvm.bswap` / `@llvm.fshl` /
// `@llvm.bitreverse` form, matching the host intrinsics the `.cpp` /
// `.rs` siblings call directly (`__builtin_popcountll` /
// `u64::count_ones` and friends). This bench measures three languages
// hitting the same native instructions, not a portable-fallback gap.
//
// 5 M iterations × 6 bit ops. Deterministic LCG drives the input so
// the final accumulator matches byte-for-byte between languages.
use std::core::bits::popcount64;
use std::core::bits::leadingZeros64;
use std::core::bits::trailingZeros64;
use std::core::bits::byteSwap64;
use std::core::bits::rotateLeft64;
use std::core::bits::bitReverse64;
fn main() : void {
let N : i32 = 5000000;
// LCG state (signed i64; wrapping arithmetic is i64-default).
// mul = 6364136223846793005, add = 1442695040888963407
// These are Knuth's MMIX constants — widely-used full-period LCG.
let mul : i64 = 6364136223846793005;
let add : i64 = 1442695040888963407;
let mut state : i64 = 12345;
let mut acc : i64 = 0;
for (i of 0..N) {
state = state * mul + add;
let x : i64 = state;
acc = acc + (popcount64(x) as i64);
acc = acc + (leadingZeros64(x) as i64);
acc = acc + (trailingZeros64(x) as i64);
acc = acc ^ byteSwap64(x);
acc = acc ^ rotateLeft64(x, 17);
acc = acc ^ bitReverse64(x);
}
println(acc);
}A pure-function call plus an invariant sub-expression buried in a variant term, hoisted out of a 100M-iteration loop by scalar LICM.
| Variant | Run | Compile | Output | ||
|---|---|---|---|---|---|
| Run time | RAM | Compile time | RAM | Binary | |
| C++ -O3 | 13 ms | 44.3 MB | 433 ms | 121.4 MB | 16 KB |
| Axle -O3 | 14 ms | 44.3 MB | 83 ms | 125.4 MB | 305 KB |
| C++ -O2 | 14 ms | 44.3 MB | 433 ms | 121.6 MB | 16 KB |
| Rust -O2 | 14 ms | 44.3 MB | 112 ms | 143.5 MB | 3865 KB |
| Rust -O3 | 14 ms | 44.3 MB | 110 ms | 140.5 MB | 3865 KB |
| Axle -O2 | 15 ms | 44.3 MB | 82 ms | 123.3 MB | 305 KB |
| Rust -O1 | 27 ms | 44.3 MB | 108 ms | 140.5 MB | 3866 KB |
| Axle -O1 | 48 ms | 44.3 MB | 74 ms | 125.1 MB | 304 KB |
| C++ -O1 | 48 ms | 44.3 MB | 431 ms | 120.3 MB | 16 KB |
| Axle -O0 | 241 ms | 44.3 MB | 70 ms | 127.3 MB | 304 KB |
| C++ -O0 | 267 ms | 44.3 MB | 417 ms | 114.4 MB | 16 KB |
| Rust -O0 | 637 ms | 44.3 MB | 89 ms | 140.8 MB | 3873 KB |
// LICM micro-benchmark — a tight loop whose per-iteration work includes
// a loop-invariant pure-function call and an invariant sub-expression
// buried in a larger term. Without hoisting, `scale(w, h)` and `w * h`
// would both be recomputed on every one of the N iterations; LICM lifts
// both into the pre-header so the loop body's only per-iteration work is
// the variant additions. Equivalent to licm_hoist.rs (same N, same
// accumulator, same printed checksum).
use std::sys::process::argc;
// Two statements (not the single `return <leaf>` shape `inline_trivial`
// substitutes away) so the call survives to LICM as a genuine `Call`
// node instead of being inlined into `w * h` first.
fn scale(a : i32, b : i32) : i32 {
let p : i32 = a * b;
return p;
}
fn main() : i32 {
// From argv: a constant count lets the backend close the recurrence and
// the loop never runs.
let n : i64 = 100000000 + (argc() as i64);
let w : i32 = 7;
let h : i32 = 6;
let mut sum : i64 = 0;
let mut i : i64 = 0;
while (i < n) {
let area : i32 = scale(w, h);
let term : i32 = w * h + (i as i32);
sum = sum + (area as i64) + (term as i64);
i = i + 1;
}
println(sum);
return 0;
}Escape-time fractal over a 13M-pixel grid — a tight floating-point inner loop.
| Variant | Run | Compile | Output | ||
|---|---|---|---|---|---|
| Run time | RAM | Compile time | RAM | Binary | |
| Axle -O3 | 279 ms | 51.3 MB | 92 ms | 122.9 MB | 308 KB |
| Axle -O2 | 280 ms | 51.3 MB | 92 ms | 123.5 MB | 308 KB |
| Axle -O1 | 330 ms | 51.3 MB | 78 ms | 122.9 MB | 307 KB |
| C++ -O3 | 447 ms | 52.4 MB | 110 ms | 97.5 MB | 16 KB |
| C++ -O2 | 449 ms | 52.4 MB | 109 ms | 97.5 MB | 16 KB |
| Rust -O2 | 461 ms | 51.2 MB | 124 ms | 148.5 MB | 3863 KB |
| Rust -O3 | 463 ms | 51.2 MB | 124 ms | 150.7 MB | 3863 KB |
| C++ -O1 | 486 ms | 52.4 MB | 103 ms | 96.6 MB | 16 KB |
| Rust -O1 | 714 ms | 51.2 MB | 120 ms | 147.4 MB | 3864 KB |
| C++ -O0 | 1.48 s | 52.4 MB | 92 ms | 91.4 MB | 16 KB |
| Axle -O0 | 1.79 s | 51.3 MB | 72 ms | 121.5 MB | 309 KB |
| Rust -O0 | 4.05 s | 51.2 MB | 98 ms | 144.8 MB | 3875 KB |
// Mandelbrot set on a 3600 × 3600 grid, max 50 iterations.
//
// Stresses pure f64 compute (zx² - zy² and 2·zx·zy form the
// canonical SIMD-friendly inner kernel), data-dependent branch
// (escape test |z|² > 4), and a 64 MiB sequential write (iter
// counts) followed by three reduction passes — the same memory-
// access shape as the k-nucleotide bench but with arithmetic
// instead of histogram updates as the per-iteration cost.
//
// Equivalent to mandelbrot.cpp / mandelbrot.rs (same dimensions,
// same reduction outputs).
fn main() : void {
let W : i32 = 3600;
let H : i32 = 3600;
let MAX_ITER : i32 = 50;
// Iteration count per pixel — written linearly, read three
// times by the reduction passes below.
let mut iters : i32[12960000] = i32[12960000];
// ── Render: per-pixel z² + c escape iteration. ──
// Coordinates picked so the visible square covers
// (-2, -2) .. (+2, +2) — the standard CLBG framing.
for (y of 0..3600) {
let cy : f64 = -2.0 + 4.0 * (y as f64) / 3600.0;
for (x of 0..3600) {
let cx : f64 = -2.0 + 4.0 * (x as f64) / 3600.0;
let mut zx : f64 = 0.0;
let mut zy : f64 = 0.0;
let mut n : i32 = 0;
let mut escaped : bool = false;
for (iter of 0..50) {
if (!escaped) {
let zx2 : f64 = zx * zx;
let zy2 : f64 = zy * zy;
if (zx2 + zy2 > 4.0) {
escaped = true;
} else {
let new_zx : f64 = zx2 - zy2 + cx;
let new_zy : f64 = 2.0 * zx * zy + cy;
zx = new_zx;
zy = new_zy;
n = n + 1;
}
}
}
iters[y * 3600 + x] = n;
}
}
// ── Reduction 1: total iteration count across the image. ──
let mut totalSink : i32 = 0;
for (idx of 0..12960000) {
totalSink = totalSink + iters[idx];
if (totalSink > 1000000000) {
totalSink = totalSink - 1000000000;
}
}
println(totalSink);
// ── Reduction 2: count of in-set pixels (n reached MAX_ITER). ──
let mut inSetCount : i32 = 0;
for (idx of 0..12960000) {
if (iters[idx] == 50) {
inSetCount = inSetCount + 1;
}
}
println(inSetCount);
// ── Reduction 3: histogram of iteration counts (51 bins). ──
let mut hist : i32[51] = i32[51];
for (idx of 0..12960000) {
hist[iters[idx]] = hist[iters[idx]] + 1;
}
let mut histSink : i32 = 0;
for (i of 0..51) {
histSink = histSink + hist[i] * i;
if (histSink > 1000000000) {
histSink = histSink - 1000000000;
}
}
println(histSink);
// Specific pixel iteration counts — deterministic cross-impl
// checks. Coordinates chosen to land on three structurally
// different points (interior, fringe, exterior).
println(iters[0]);
println(iters[2000 * 3600 + 1500]);
println(iters[3500 * 3600 + 3500]);
println("Done!");
}Transcendental math (sin / cos / sqrt / pow) hammered in a hot loop.
| Variant | Run | Compile | Output | ||
|---|---|---|---|---|---|
| Run time | RAM | Compile time | RAM | Binary | |
| Rust -O2 | 261 ms | 44.1 MB | 108 ms | 138.8 MB | 3894 KB |
| Rust -O3 | 261 ms | 44.1 MB | 109 ms | 138.5 MB | 3894 KB |
| Axle -O2 | 262 ms | 44.1 MB | 95 ms | 123.5 MB | 309 KB |
| Axle -O3 | 263 ms | 44.1 MB | 96 ms | 125.3 MB | 309 KB |
| Rust -O1 | 264 ms | 44.1 MB | 108 ms | 140.7 MB | 3894 KB |
| Axle -O1 | 265 ms | 44.1 MB | 83 ms | 124.7 MB | 308 KB |
| C++ -O2 | 270 ms | 44.1 MB | 266 ms | 110.0 MB | 16 KB |
| C++ -O3 | 270 ms | 44.1 MB | 268 ms | 110.0 MB | 16 KB |
| C++ -O1 | 273 ms | 44.1 MB | 264 ms | 109.4 MB | 16 KB |
| Axle -O0 | 342 ms | 44.1 MB | 76 ms | 123.4 MB | 309 KB |
| C++ -O0 | 352 ms | 44.1 MB | 252 ms | 105.5 MB | 16 KB |
| Rust -O0 | 411 ms | 44.1 MB | 94 ms | 138.4 MB | 3904 KB |
// Math kernel — N transcendental evaluations + integer abs/min/max
// reductions. Exercises the Phase 1 pure-Axle math module end to end:
// * libm transcendentals via inline `@link(symbol = …)` (sin, cos, tan,
// sqrt, cbrt, exp, log, log10, hypot, atan2, …)
// * pure-Axle abs / min / max / sign / classification on i64
//
// All three impls (axle / cpp / rust) link the same libm, so
// transcendental outputs are bit-identical on a given libc. We
// print integer-cast sums (×1e9 then `as i64`) to stay deterministic
// across impls while still surfacing accumulated floating-point
// drift bugs.
//
// Equivalent to math_intensive.cpp / math_intensive.rs (same N,
// same accumulators, same output lines).
use std::numeric::math;
// The three accumulated sums below differ from the C++ / Rust siblings in the
// last digits; the ten sample points and both integer reductions agree. Each
// language sums floats its own way — that is what is being measured.
fn main() : void {
let N : i32 = 3400000;
// ── Transcendental accumulator. ──
// Each iteration evaluates sin / cos / tan / sqrt / log / exp /
// hypot / atan2 on a deterministic seed derived from `i`. The
// running sum threads through every operation so a regression in
// any libm wrapper surfaces in the final checksum.
let mut trig_sum : f64 = 0.0;
let mut exp_sum : f64 = 0.0;
let mut mix_sum : f64 = 0.0;
for (i of 0..3400000) {
let x : f64 = ((i + 1) as f64) * 0.0001; // 0.0001 .. 400.0
// `math::sinCos(x)` is two libm calls, `sin` then `cos`: the GNU
// `sincos` it would fuse into is not in the MSVC / lld libm, and LLVM
// only forms it on targets that provide one. The pair is kept so the
// bench measures both transcendentals per element.
let sc : (f64, f64) = math::sinCos(x);
let s : f64 = sc.0;
let c : f64 = sc.1;
let t : f64 = (x * 0.5).tan();
trig_sum = trig_sum + s * c + t * 0.001;
let lg : f64 = (x + 1.0).ln();
let ex : f64 = (-x * 0.001).exp(); // 1.0 .. ~0.67
exp_sum = exp_sum + lg + ex;
let sq : f64 = (x + 1.0).sqrt();
let cb : f64 = (x + 1.0).cbrt();
let h : f64 = math::hypot(s, c); // ≈ 1.0 every iter
let a2 : f64 = math::atan2(s, c); // ≈ x mod 2π
mix_sum = mix_sum + sq - cb + h + a2;
}
// Cast ×1e9 → i64 to drop sub-nanounit noise while still letting
// libm drift surface as a sum-of-ULP mismatch.
println((trig_sum * 1000000000.0).truncToInt());
println((exp_sum * 1000000000.0).truncToInt());
println((mix_sum * 1000000000.0).truncToInt());
// ── Specific sample points — sanity-pin libm vs the reference. ──
// Cast ×1e15 → i64 so a single-ULP libm drift surfaces as a
// unit-level mismatch.
println(((1.0).sin() * 1000000000000000.0).truncToInt());
println(((1.5).cos() * 1000000000000000.0).truncToInt());
println(((0.5).tan() * 1000000000000000.0).truncToInt());
println(((2.0).sqrt() * 1000000000000000.0).truncToInt());
println(((27.0).cbrt() * 1000000000000000.0).truncToInt());
println(((1.0).exp() * 1000000000000000.0).truncToInt());
println(((2.0).ln() * 1000000000000000.0).truncToInt());
println(((1000.0).log10() * 1000000000000000.0).truncToInt());
println((math::hypot(3.0, 4.0) * 1000000000000000.0).truncToInt());
println((math::atan2(1.0, 1.0) * 1000000000000000.0).truncToInt());
// ── Integer reductions: abs / min / max / sign. ──
// Same N, deterministic input distribution so any branch-prediction
// miscompile or sign-handling bug surfaces in `int_sum`.
let mut int_sum : i64 = 0;
for (i of 0..3400000) {
let a : i64 = (i as i64) - 2000000;
let b : i64 = (i as i64) * 3 - 5000000;
int_sum = int_sum + a.abs();
int_sum = int_sum + a.min(b);
int_sum = int_sum + a.max(b);
let s : f64 = (a as f64).sign();
int_sum = int_sum + s.truncToInt();
}
println(int_sum);
// ── Floor / ceil / trunc / round on a swept input. ──
let mut round_sum : i64 = 0;
for (i of 0..1000000) {
let x : f64 = ((i as f64) - 500000.0) * 0.001; // -500.0 .. +500.0
round_sum = round_sum + x.floorToInt();
round_sum = round_sum + x.ceilToInt();
round_sum = round_sum + x.truncToInt();
round_sum = round_sum + x.round();
}
println(round_sum);
// NOTE: a `isFinite` / `isInfinite` / `isNaN` sweep belongs here
// logically, but axle's codegen currently folds the `x != x` self-
// compare to `false` under fast-math, breaking IEEE 754 NaN
// semantics. Cross-impl outputs would diverge by ~9 (axle counts
// +∞ as Finite). Tracked as a separate codegen bug — re-enable
// the classification reduction here once the fold is gated behind
// a `-ffast-math`-style opt-in.
println("Done!");
}