Benchmarks

Numerics benchmarks

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

Numerics

bits_intensive

Bit-twiddling throughput — popcount / clz / ctz / bswap / rotate / bitreverse, all three languages routed through the matching native intrinsic.

VariantRunCompileOutput
Run timeRAMCompile timeRAMBinary
Axle -O312 ms46.1 MB77 ms123.1 MB303 KB
Rust -O212 ms46.1 MB91 ms141.2 MB3862 KB
Axle -O113 ms46.1 MB74 ms124.8 MB303 KB
Axle -O213 ms46.1 MB76 ms124.8 MB303 KB
Rust -O113 ms46.1 MB93 ms137.6 MB3862 KB
Rust -O313 ms46.1 MB91 ms139.3 MB3862 KB
Axle -O039 ms46.1 MB71 ms123.3 MB303 KB
C++ -O245 ms46.1 MB96 ms96.5 MB16 KB
C++ -O345 ms46.1 MB94 ms96.6 MB16 KB
Rust -O047 ms46.1 MB85 ms139.1 MB3865 KB
C++ -O1161 ms46.1 MB91 ms95.5 MB16 KB
C++ -O0581 ms46.1 MB85 ms90.6 MB16 KB
▸ Source
// 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);
}

licm_hoist

A pure-function call plus an invariant sub-expression buried in a variant term, hoisted out of a 100M-iteration loop by scalar LICM.

VariantRunCompileOutput
Run timeRAMCompile timeRAMBinary
C++ -O313 ms44.3 MB433 ms121.4 MB16 KB
Axle -O314 ms44.3 MB83 ms125.4 MB305 KB
C++ -O214 ms44.3 MB433 ms121.6 MB16 KB
Rust -O214 ms44.3 MB112 ms143.5 MB3865 KB
Rust -O314 ms44.3 MB110 ms140.5 MB3865 KB
Axle -O215 ms44.3 MB82 ms123.3 MB305 KB
Rust -O127 ms44.3 MB108 ms140.5 MB3866 KB
Axle -O148 ms44.3 MB74 ms125.1 MB304 KB
C++ -O148 ms44.3 MB431 ms120.3 MB16 KB
Axle -O0241 ms44.3 MB70 ms127.3 MB304 KB
C++ -O0267 ms44.3 MB417 ms114.4 MB16 KB
Rust -O0637 ms44.3 MB89 ms140.8 MB3873 KB
▸ Source
// 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;
}

mandelbrot

Escape-time fractal over a 13M-pixel grid — a tight floating-point inner loop.

VariantRunCompileOutput
Run timeRAMCompile timeRAMBinary
Axle -O3279 ms51.3 MB92 ms122.9 MB308 KB
Axle -O2280 ms51.3 MB92 ms123.5 MB308 KB
Axle -O1330 ms51.3 MB78 ms122.9 MB307 KB
C++ -O3447 ms52.4 MB110 ms97.5 MB16 KB
C++ -O2449 ms52.4 MB109 ms97.5 MB16 KB
Rust -O2461 ms51.2 MB124 ms148.5 MB3863 KB
Rust -O3463 ms51.2 MB124 ms150.7 MB3863 KB
C++ -O1486 ms52.4 MB103 ms96.6 MB16 KB
Rust -O1714 ms51.2 MB120 ms147.4 MB3864 KB
C++ -O01.48 s52.4 MB92 ms91.4 MB16 KB
Axle -O01.79 s51.3 MB72 ms121.5 MB309 KB
Rust -O04.05 s51.2 MB98 ms144.8 MB3875 KB
▸ Source
// 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!");
}

math_intensive

Transcendental math (sin / cos / sqrt / pow) hammered in a hot loop.

VariantRunCompileOutput
Run timeRAMCompile timeRAMBinary
Rust -O2261 ms44.1 MB108 ms138.8 MB3894 KB
Rust -O3261 ms44.1 MB109 ms138.5 MB3894 KB
Axle -O2262 ms44.1 MB95 ms123.5 MB309 KB
Axle -O3263 ms44.1 MB96 ms125.3 MB309 KB
Rust -O1264 ms44.1 MB108 ms140.7 MB3894 KB
Axle -O1265 ms44.1 MB83 ms124.7 MB308 KB
C++ -O2270 ms44.1 MB266 ms110.0 MB16 KB
C++ -O3270 ms44.1 MB268 ms110.0 MB16 KB
C++ -O1273 ms44.1 MB264 ms109.4 MB16 KB
Axle -O0342 ms44.1 MB76 ms123.4 MB309 KB
C++ -O0352 ms44.1 MB252 ms105.5 MB16 KB
Rust -O0411 ms44.1 MB94 ms138.4 MB3904 KB
▸ Source
// 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!");
}