Benchmarks

Collections benchmarks

7 programs measured with axle bench: arraylist_intensive, hashmap_int, hashmap_mixed, hashmap_string, hashmap_string_owned, hashset_intensive, strmap_intensive. Run time, peak RAM at compile and run, and binary size, with the exact source for each language.

Benchmarks for v0.23.0

Collections

arraylist_intensive

ArrayList push / get / remove churn with geometric growth.

VariantRunCompileOutput
Run timeRAMCompile timeRAMBinary
Axle -O252 ms44.5 MB114 ms121.5 MB309 KB
Axle -O353 ms44.5 MB116 ms125.1 MB308 KB
C++ -O266 ms44.5 MB530 ms122.9 MB17 KB
C++ -O366 ms44.5 MB529 ms122.8 MB17 KB
Rust -O271 ms44.5 MB116 ms146.3 MB3864 KB
Rust -O374 ms44.5 MB117 ms144.5 MB3864 KB
Rust -O1113 ms44.5 MB107 ms147.1 MB3864 KB
C++ -O1125 ms44.5 MB522 ms122.5 MB17 KB
Axle -O1141 ms44.5 MB104 ms123.3 MB309 KB
Axle -O0210 ms44.5 MB80 ms122.3 MB310 KB
C++ -O0250 ms44.5 MB502 ms118.7 MB24 KB
Rust -O0372 ms44.5 MB96 ms141.4 MB3871 KB
▸ Source
// EXPECTED_EXIT: 0
// Intensive ArrayList benchmark — shared logic with arraylist_intensive.cpp
// and arraylist_intensive.rs (run via `axle bench --compare cpp,rust`).
//
// Workload:
//   1. 2,000,000 add() calls filling an ArrayList<i64> — capacity
//      doubling + reallocation stress (~30+ resize events).
//   2. 2,000,000 LCG-driven get() reads at scattered indices,
//      accumulating a pre-write checksum.
//   3. 500,000 LCG-driven set() overwrites at scattered indices.
//   4. 2,000,000 more LCG-driven reads, accumulating a post-write
//      checksum so write effects are visible in the cross-impl
//      comparison.
// The three printed lines (final size, pre-write checksum,
// post-write checksum) must be byte-identical across all three
// languages.

use std::collections::ArrayList;

fn main() : i32 ! IndexOutOfBoundsException {
    let inserts : i64 = 2000000;
    let reads : i64 = 2000000;
    let writes : i64 = 500000;

    let l : ArrayList<i64> = new ArrayList<i64>();

    let mut seed : i64 = 12345;
    let mut i : i64 = 0;
    while (i < inserts) {
        seed = (seed * 48271) % 2147483647;
        l.add(seed % 100000);
        i = i + 1;
    }
    let size64 : i64 = l.size();
    println(l.size());

    let mut seed_r : i64 = 33333;
    let mut sum1 : i64 = 0;
    let mut j : i64 = 0;
    while (j < reads) {
        seed_r = (seed_r * 48271) % 2147483647;
        let idx : i32 = ((seed_r % size64) as i32);
        sum1 = sum1 + (l.get(idx) ?? 0);
        j = j + 1;
    }
    println(sum1);

    let mut seed_w : i64 = 55555;
    let mut w : i64 = 0;
    while (w < writes) {
        seed_w = (seed_w * 48271) % 2147483647;
        let widx : i32 = ((seed_w % size64) as i32);
        let wval : i64 = seed_w % 100000;
        l.set(widx, wval);
        w = w + 1;
    }

    let mut seed_r2 : i64 = 99999;
    let mut sum2 : i64 = 0;
    let mut k : i64 = 0;
    while (k < reads) {
        seed_r2 = (seed_r2 * 48271) % 2147483647;
        let kidx : i32 = ((seed_r2 % size64) as i32);
        sum2 = sum2 + (l.get(kidx) ?? 0);
        k = k + 1;
    }
    println(sum2);
    return 0;
}

hashmap_int

HashMap<i32, i32> insert + lookup churn.

VariantRunCompileOutput
Run timeRAMCompile timeRAMBinary
Axle -O3105 ms45.5 MB157 ms127.5 MB310 KB
Axle -O2110 ms45.5 MB156 ms125.3 MB310 KB
Axle -O1118 ms45.5 MB135 ms126.1 MB310 KB
Rust -O3195 ms45.5 MB178 ms162.6 MB3884 KB
Rust -O2196 ms45.5 MB165 ms165.2 MB3883 KB
Rust -O1205 ms45.5 MB162 ms164.0 MB3883 KB
Axle -O0262 ms45.5 MB89 ms126.1 MB313 KB
C++ -O3418 ms45.5 MB588 ms123.0 MB18 KB
C++ -O2427 ms45.5 MB583 ms123.2 MB18 KB
C++ -O1501 ms45.5 MB571 ms122.6 MB18 KB
C++ -O01.19 s45.5 MB540 ms119.9 MB46 KB
Rust -O01.21 s45.5 MB119 ms155.5 MB3920 KB
▸ Source
// EXPECTED_EXIT: 0
// HashMap<i64, i64> stress test — exercises the stdlib's pure-Axle
// SwissTable on the integer-key path (`hash_key(i64)` → inline
// SplitMix64 with the process-random seed).
//
// Workload :
//   1. 2,000,000 inserts into a HashMap<i64, i64>; keys drawn from
//      an 800k space by a deterministic LCG (heavy overwrite +
//      rehash pressure, ~800k live entries at end).
//   2. 2,000,000 single-probe lookups via `get(k)` + a non-null guard,
//      mirroring the `if let Some(v) = m.get(&k)` shape of the Rust
//      reference: one hash probe per iteration, the value summed only
//      when present (`get` returns `V | null`, smart-cast to `V` inside
//      the guard). `axle bench --compare rust` then measures the table,
//      not call overhead.
//
// The two printed lines (live size, checksum) are byte-identical
// across `hashmap_int.cpp` / `hashmap_int.rs` so
// `axle bench --compare cpp,rust` can cross-validate.
//
// **What this ratio is, and is not.** Both sides hash with a keyed function, so
// there is no HashDoS asymmetry: Axle's `hash_key` inlines
// `splitmix64(x ^ k0) ^ k1` off a 128-bit OS-CSPRNG seed drawn in `main`'s
// prologue, and Rust's default `RandomState` is keyed SipHash-1-3. But they are
// very different cost points — ~6 register operations against one compression
// round plus three finalisation rounds — and on an integer key that is most of
// the work.
//
// Measured, by giving the Rust reference Axle's own keyed SplitMix through a
// custom `BuildHasher` (identical output, 135 / 194 / 117 ms):
// against `HashMap::new()` Axle is 1.44× ahead, and against the same hash Rust is
// 1.15× ahead. So this bench compares **two hash choices**, not two hash tables
// and not two compilers. `hashmap_string` is the one to quote for the table,
// because there both sides run SipHash-1-3.

use std::collections::HashMap;

fn main() : i32 {
    let inserts : i64 = 2000000;
    let lookups : i64 = 2000000;
    let keyspace : i64 = 800000;

    let m : HashMap<i64, i64> = new HashMap<i64, i64>();

    let mut seed : i64 = 12345;
    let mut i : i64 = 0;
    while (i < inserts) {
        seed = (seed * 48271) % 2147483647;
        let key : i64 = seed % keyspace;
        let val : i64 = seed % 100000;
        m.put(key, val);
        i = i + 1;
    }

    let mut sum : i64 = 0;
    let mut j : i64 = 0;
    while (j < lookups) {
        let k : i64 = j % keyspace;
        let v : i64 | null = m.get(k);
        if (v != null) { sum = sum + v; }
        j = j + 1;
    }

    println(m.size());
    println(sum);
    return 0;
}

hashmap_mixed

Mixed HashMap workload — interleaved insert / erase / rehash stress.

VariantRunCompileOutput
Run timeRAMCompile timeRAMBinary
Axle -O2192 ms44.1 MB194 ms125.3 MB311 KB
Axle -O3196 ms44.1 MB219 ms127.7 MB311 KB
Axle -O1277 ms44.1 MB148 ms125.9 MB311 KB
Rust -O3470 ms44.1 MB192 ms161.0 MB3885 KB
Rust -O2489 ms44.1 MB191 ms162.0 MB3884 KB
Rust -O1525 ms44.1 MB176 ms163.8 MB3884 KB
Axle -O0680 ms44.1 MB94 ms127.9 MB314 KB
C++ -O31.01 s44.1 MB653 ms123.4 MB21 KB
C++ -O21.02 s44.1 MB627 ms123.3 MB18 KB
C++ -O11.20 s44.1 MB606 ms123.2 MB18 KB
C++ -O04.40 s44.1 MB551 ms120.1 MB47 KB
Rust -O06.23 s44.1 MB127 ms158.9 MB3922 KB
▸ Source
// EXPECTED_EXIT: 0
// HashMap<i64,i64> mixed alloc/dealloc stress test.
//
// A deliberately convoluted call graph — orchestrator → brew → {stir,
// probe} → lcg, plus orchestrator → forge → stir — drives many HashMap
// lifecycles through nested loops so the teardown machinery is hammered:
//
//   * `brew` allocates a LOCAL map, fills it through a doubly-nested
//     loop (≥1000 puts → forces the internal meta/keys/values buffers to
//     rehash several times), probes it ≥30× via `get` + a non-null guard
//     (the `if let Some(v)` shape), then lets
//     it fall out of scope — `drop_insertion` emits the `StackDtor` that
//     frees the three buffers. Repeated `REPS` times = `REPS` full
//     alloc→grow→free cycles.
//   * `forge` allocates a map, fills it, and RETURNS it: the value
//     ESCAPES its frame, so the caller reads from it after the callee's
//     stack is gone — exercises that an owned collection survives the
//     escape boundary intact.
//
// Everything is driven by a deterministic LCG threaded by value through
// the call chain, so the two printed lines (accumulated checksum, total
// distinct-key volume) are byte-identical to `hashmap_mixed.rs`.
// The reference is STRICTLY algorithmically equal — same LCG, same loop
// bounds, same put / get / size order — so `axle bench --compare
// rust` cross-validates the output.
//
// **What this ratio is, and is not.** Both sides hash with a keyed function, so
// there is no HashDoS asymmetry: Axle's `hash_key` inlines
// `splitmix64(x ^ k0) ^ k1` off a 128-bit OS-CSPRNG seed drawn in `main`'s
// prologue, and Rust's default `RandomState` is keyed SipHash-1-3. But they are
// very different cost points — ~6 register operations against one compression
// round plus three finalisation rounds — and on an integer key that is most of
// the work.
//
// Measured, by giving the Rust reference Axle's own keyed SplitMix through a
// custom `BuildHasher` (identical output, 375 / 495 / 307 ms):
// against `HashMap::new()` Axle is 1.32× ahead, and against the same hash Rust is
// 1.22× ahead. So this bench compares **two hash choices**, not two hash tables
// and not two compilers. `hashmap_string` is the one to quote for the table,
// because there both sides run SipHash-1-3.
//
// **And this ratio is specific to the map size, not to the volume.** The maps here
// hold 1,200–4,000 entries — about 68 KB of table, comfortably inside a 512 KB L2
// — which is where Axle's cheap hash dominates and its struct-of-arrays layout
// costs almost nothing. Multiplying the number of map lifecycles changes nothing
// (1.28× at ten times the runs, and again at a hundred, out to a 40-second run).
// Multiplying the map *size* by ten used to invert it — at ~1.1 MB of table Axle
// fell behind even the default-hasher reference (6,186 against 5,516 ms), because
// a hit read `meta`, `keys` and `values` from three separate arrays where
// hashbrown reads a ctrl byte and one 16-byte `(K, V)` entry. A scalar key/value
// pair is now laid out as one array of entries
// (`instantiate::fuse_entries`), which closes it: 6,450 → 4,632 ms on that
// variant, and 379 → 332 ms here.
//
// The mechanism is not the one the cache-line argument predicts, and the control
// says so: a **single** long-lived map of the same L2 size gains nothing (1.00×).
// What this workload buys from the fusion is one `malloc` and one `free` per map
// instead of two, across 7,200 map lifecycles.

use std::collections::HashMap;

// Park–Miller minimal-standard LCG (matches the other hashmap benches).
fn lcg(s : i64) : i64 {
    return (s * 48271) % 2147483647;
}

// Insert `rounds` entries into `m`, threading and returning the seed so
// the caller keeps the deterministic stream going.
fn stir(mut m : HashMap<i64, i64>, seed : i64, rounds : i64, keyspace : i64) : i64 {
    let mut s : i64 = seed;
    let mut i : i64 = 0;
    while (i < rounds) {
        s = lcg(s);
        let key : i64 = s % keyspace;
        let val : i64 = s % 100000;
        m.put(key, val);
        i = i + 1;
    }
    return s;
}

// `count` single-probe lookups; returns the checksum of the hits.
fn probe(m : HashMap<i64, i64>, seed : i64, count : i64, keyspace : i64) : i64 {
    let mut s : i64 = seed;
    let mut sum : i64 = 0;
    let mut i : i64 = 0;
    while (i < count) {
        s = lcg(s);
        let k : i64 = s % keyspace;
        let v : i64 | null = m.get(k);
        if (v != null) { sum = sum + v; }
        i = i + 1;
    }
    return sum;
}

// Allocate a local map, fill it through a nested loop (outer × inner ≥
// 1000 puts), probe it ≥ 30×, then drop it at scope exit. Returns a
// scalar checksum so the map itself never escapes this frame.
fn brew(seed : i64, outer : i64, inner : i64, keyspace : i64) : i64 {
    let m : HashMap<i64, i64> = new HashMap<i64, i64>();
    let mut s : i64 = seed;
    let mut a : i64 = 0;
    while (a < outer) {
        s = stir(m, s, inner, keyspace);
        a = a + 1;
    }
    let hits : i64 = probe(m, s, 30, keyspace);
    let result : i64 = hits + m.size();
    return result;
}

// Allocate a map, fill it with ≥ 1000 entries, and hand ownership back to
// the caller — the map ESCAPES this frame.
fn forge(seed : i64, rounds : i64, keyspace : i64) : HashMap<i64, i64> {
    let m : HashMap<i64, i64> = new HashMap<i64, i64>();
    stir(m, seed, rounds, keyspace);
    return m;
}

// Orchestrate `reps` brews plus periodic escaping forges, threading the
// LCG from `seed0` and accumulating a checksum + the total live-key
// volume.
fn concoct(reps : i64, keyspace : i64, seed0 : i64) : i64 {
    let mut total : i64 = 0;
    let mut volume : i64 = 0;
    let mut seed : i64 = seed0;
    let mut r : i64 = 0;
    while (r < reps) {
        seed = lcg(seed);
        let outer : i64 = 2 + (seed % 3);
        let inner : i64 = 600 + (seed % 400);
        total = total + brew(seed, outer, inner, keyspace);

        // Every third rep, forge an escaping map and probe it.
        if ((r % 3) == 0) {
            seed = lcg(seed);
            let big : HashMap<i64, i64> = forge(seed, 1200, keyspace);
            total = total + probe(big, seed, 30, keyspace);
            volume = volume + big.size();
        }
        r = r + 1;
    }
    return total + volume;
}

fn main() : i32 {
    let keyspace : i64 = 50000;
    let reps : i64 = 150;
    let outer_runs : i64 = 36;

    // Thread one LCG across every run so each `concoct` sees a distinct
    // seed — 5,400 brewed maps + 1,800 escaping forges, every one
    // allocating, rehashing, and (for the locals) freeing its three
    // internal buffers. Sized so the workload stays well under the
    // per-run budget while remaining clear of timer noise.
    let mut grand : i64 = 0;
    let mut seed : i64 = 777767;
    let mut run : i64 = 0;
    while (run < outer_runs) {
        seed = lcg(seed);
        grand = grand + concoct(reps, keyspace, seed);
        run = run + 1;
    }

    println(grand);
    println(reps * outer_runs);
    return 0;
}

hashmap_string

HashMap with string keys — hashing + probing over text.

VariantRunCompileOutput
Run timeRAMCompile timeRAMBinary
Axle -O2204 ms45.6 MB198 ms128.1 MB321 KB
Axle -O3204 ms45.6 MB209 ms126.1 MB321 KB
Axle -O1214 ms45.6 MB157 ms126.2 MB321 KB
Rust -O3232 ms45.6 MB213 ms169.3 MB3888 KB
C++ -O1243 ms45.6 MB712 ms125.8 MB24 KB
C++ -O3245 ms45.6 MB741 ms125.8 MB24 KB
C++ -O2246 ms45.6 MB733 ms126.3 MB24 KB
Rust -O2246 ms45.6 MB213 ms170.3 MB3887 KB
Rust -O1257 ms45.6 MB196 ms169.4 MB3888 KB
Axle -O0272 ms45.6 MB95 ms126.2 MB325 KB
C++ -O0499 ms45.6 MB635 ms122.1 MB80 KB
Rust -O0546 ms45.6 MB132 ms166.9 MB3938 KB
▸ Source
// EXPECTED_EXIT: 0
// HashMap<string, i64> stress test — exercises the stdlib's pure-Axle
// SwissTable on the string-key path (`hash_key(string)` → the keyed
// pure-Axle `hashStringSeeded` mix).
//
// **What this measures: the table and the hasher, under overwrite pressure.**
// 500,000 puts are drawn from a 200,000-key pool, so only the first 200,000 take
// the insert branch and ~300,000 overwrite.
//
// **Why the comparison is apples-to-apples**, checked rather than assumed:
//
// * **Same hash.** `hashStringSeeded` is SipHash-1-3 — one compression round per
//   message word, three finalisation rounds — which is exactly what Rust's default
//   `RandomState` runs. Both are keyed, so neither trades HashDoS resistance for
//   speed.
// * **Same key ownership.** Neither side borrows. Rust's `HashMap<String, i64>`
//   takes an owned key, so the reference writes `keys[..].clone()` on every insert;
//   Axle's container acquires its own payload, so `string_acquire` inserts a
//   `__string_clone` at the same call site. 500,000 copies each, of which ~300,000
//   are freed at once by the overwrite — the displaced key on the Axle side, the
//   passed-and-dropped key on Rust's. Verified in the emitted code on both sides
//   (`__rust_alloc` + `memcpy` + `__rust_dealloc` against `malloc` + `llvm.memcpy`
//   + `free`), because a copy the optimiser removes would be a copy only one side
//   pays.
// * **Same host ISA.** `axle build -O ≥ 2` on a host target defaults to the host
//   CPU, matching the `-march=native` / `-C target-cpu=native` the harness
//   passes the other two.
// * **Table families differ.** Axle's SwissTable and hashbrown's open
//   addressing against libstdc++'s node-based chained buckets.
//
// So this one is the table and the hasher, and it is the string-keyed bench to
// quote. Its siblings are not interchangeable with it: `hashmap_string_owned` runs
// the all-distinct draw where every put stores, and `hashmap_int` compares two
// **different keyed** hashes — Axle's integer path inlines
// `splitmix64(x ^ k0) ^ k1` off the process-random seed, where Rust runs keyed
// SipHash-1-3 over the eight bytes. Both resist HashDoS; they cost very different
// amounts, so that bench's ratio carries a hashing difference this one does not.
//
// **And the operating point matters.** 200,000 keys is where Axle's margin peaks on
// this machine, because it is where Rust's table (8.4 MB) has outgrown the 16 MiB
// L3 slice that Axle's (4.2 MB) still sits inside. Holding the workload shape and
// sweeping the pool: 1.04× at 50,000 keys, 1.24× at 100,000, 1.57× here, then back
// down through 1.32× at 400,000 and 1.17× at 700,000 to 1.10× at 1,000,000, where
// both are DRAM-bound and a miss costs the same on either side. Quoting this point
// alone reports the maximum, not the shape.
//
// Workload :
//   1. Pre-allocate `keyspace` string keys via `i.toString()`
//      so the put/get loop measures the HashMap algorithm, not
//      string allocation.
//   2. 500,000 inserts into a HashMap<string, i64> using keys
//      drawn from that pool by a deterministic LCG (heavy
//      overwrite + rehash pressure).
//   3. 500,000 single-probe lookups via `get(k)` + a non-null guard,
//      mirroring the `if let Some(v) = m.get(k)` shape of the Rust
//      reference (one hash probe per iteration; the value summed only
//      when present).
//
// 4× smaller than `hashmap_int` because string hashing /
// equality is intrinsically ~4× more work per op vs i64 (Rust
// hashbrown shows the same ratio).
//
// The two printed lines (live size, checksum) are byte-identical
// across `hashmap_string.rs` so `axle bench --compare rust` can
// cross-validate.

use std::collections::HashMap;

fn main() : i32 {
    let inserts : i64 = 500000;
    let lookups : i64 = 500000;
    let keyspace : i64 = 200000;

    // Pre-allocate the key pool — one string per (0..keyspace).
    let mut keys : string[] = new string[keyspace];
    let mut p : i64 = 0;
    while (p < keyspace) {
        keys[p] = p.toString();
        p = p + 1;
    }

    let m : HashMap<string, i64> = new HashMap<string, i64>();

    let mut seed : i64 = 12345;
    let mut i : i64 = 0;
    while (i < inserts) {
        seed = (seed * 48271) % 2147483647;
        let key : string = keys[seed % keyspace];
        let val : i64 = seed % 100000;
        m.put(key, val);
        i = i + 1;
    }

    let mut sum : i64 = 0;
    let mut j : i64 = 0;
    while (j < lookups) {
        let k : string = keys[j % keyspace];
        let v : i64 | null = m.get(k);
        if (v != null) { sum = sum + v; }
        j = j + 1;
    }

    println(m.size());
    println(sum);
    return 0;
}

hashmap_string_owned

HashMap with string keys, all distinct — every put takes the insert branch and acquires its own copy of the key.

VariantRunCompileOutput
Run timeRAMCompile timeRAMBinary
Rust -O3258 ms92.0 MB210 ms171.5 MB3888 KB
Rust -O2264 ms92.1 MB207 ms168.7 MB3887 KB
Rust -O1276 ms92.1 MB194 ms169.0 MB3888 KB
Axle -O3291 ms59.8 MB205 ms126.4 MB321 KB
C++ -O1294 ms54.1 MB706 ms125.7 MB24 KB
Axle -O2295 ms59.8 MB196 ms126.1 MB321 KB
C++ -O3297 ms54.1 MB730 ms126.0 MB24 KB
C++ -O2300 ms54.1 MB728 ms126.2 MB24 KB
Axle -O1303 ms59.8 MB156 ms126.1 MB321 KB
Axle -O0378 ms59.8 MB94 ms126.1 MB325 KB
C++ -O0602 ms54.1 MB635 ms122.4 MB80 KB
Rust -O0678 ms92.1 MB132 ms166.4 MB3937 KB
▸ Source
// EXPECTED_EXIT: 0
// The all-distinct half of the string-keyed HashMap comparison.
//
// **What this measures: the insert path, every key new.** `keyspace ==
// inserts`, so all 500,000 puts take the insert branch and every one of them
// allocates: the map acquires a copy of the key it stores. The companion
// `hashmap_string` draws 500,000 puts from a 200,000-key pool, so only the
// first 200,000 allocate and the rest are overwrites — the table and hasher
// question. Neither number answers the other's, which is why both are
// published.
//
// **Both languages copy at the same place, which is what makes the comparison
// fair here.** Rust's `HashMap<String, i64>` requires an owned `String`, so the
// copy is the `clone()` written at the call site. Axle reaches the same shape
// without the caller writing anything: the key comes from a surviving pool
// entry, so `hir_passes::string_acquire` rewrites the put into
// `put(__string_clone(k), v)` — a copy at the call site too. Same allocation,
// same byte copy, and on *this* bench the same count, because `keyspace ==
// inserts` makes every call a store.
//
// That last equality is why this bench and not `hashmap_string` is the one to
// read for the copy's cost: there, 500,000 calls produce only 200,000 stores, so
// ~300,000 payloads are copied and freed at once. Both languages pay that —
// Rust's `insert` drops the key it was handed on an overwrite, Axle's reclaim
// frees the displaced one — so it cancels in the comparison and only muddies the
// per-stored-key number this bench reports.
//
// No `concat("")` in front of the pool entry: forcing a second copy would
// double-count the exact cost this bench exists to report.

use std::collections::HashMap;

fn main() : i32 {
    let inserts : i64 = 500000;
    let lookups : i64 = 500000;
    let keyspace : i64 = 500000;

    // Pre-allocate the key pool — one string per (0..keyspace).
    let mut keys : string[] = new string[keyspace];
    let mut p : i64 = 0;
    while (p < keyspace) {
        keys[p] = p.toString();
        p = p + 1;
    }

    let m : HashMap<string, i64> = new HashMap<string, i64>();

    let mut i : i64 = 0;
    while (i < inserts) {
        // The pool entry is handed over borrowed; `put` acquires the copy it
        // keeps. The pool stays valid and owns its own strings throughout.
        m.put(keys[i], i % 100000);
        i = i + 1;
    }

    let mut sum : i64 = 0;
    let mut j : i64 = 0;
    while (j < lookups) {
        let k : string = keys[j % keyspace];
        let v : i64 | null = m.get(k);
        if (v != null) { sum = sum + v; }
        j = j + 1;
    }

    println(m.size());
    println(sum);
    return 0;
}

hashset_intensive

HashSet membership tests and insertion churn.

VariantRunCompileOutput
Run timeRAMCompile timeRAMBinary
Axle -O393 ms43.9 MB160 ms128.2 MB310 KB
Axle -O195 ms43.9 MB132 ms127.4 MB310 KB
Axle -O295 ms43.9 MB159 ms128.1 MB310 KB
Rust -O3162 ms43.9 MB190 ms163.1 MB3885 KB
Rust -O2172 ms43.9 MB171 ms161.1 MB3883 KB
Rust -O1176 ms43.9 MB168 ms163.7 MB3883 KB
Axle -O0224 ms43.9 MB89 ms126.0 MB313 KB
C++ -O3520 ms43.9 MB601 ms123.1 MB18 KB
C++ -O2527 ms43.9 MB598 ms122.9 MB18 KB
C++ -O1607 ms43.9 MB586 ms122.6 MB18 KB
Rust -O01.40 s43.9 MB125 ms156.1 MB3923 KB
C++ -O01.61 s43.9 MB551 ms119.7 MB48 KB
▸ Source
// EXPECTED_EXIT: 0
// Intensive HashSet benchmark — shared logic with hashset_intensive.cpp
// and hashset_intensive.rs (run via `axle bench --compare cpp,rust`).
//
// Workload:
//   1. 2,000,000 inserts into a HashSet<i64>, keys drawn from an
//      800k space by a deterministic LCG — heavy dedup + rehash
//      pressure (~800k live entries).
//   2. 2,000,000 contains() probes over a 1.6M space (~50% miss rate)
//      accumulating a checksum that depends on membership.
//   3. 500,000 LCG-driven remove() calls followed by 500,000
//      LCG-driven add() calls — exercises the delete + re-add path.
// The three printed lines (size after inserts, checksum, size after
// the remove/add cycle) must be byte-identical across all three
// languages.

use std::collections::HashSet;

fn main() : i32 {
    let inserts : i64 = 2000000;
    let probes : i64 = 2000000;
    let cycles : i64 = 500000;
    let keyspace : i64 = 800000;
    let probespace : i64 = 1600000;

    let s : HashSet<i64> = new HashSet<i64>();

    let mut seed : i64 = 12345;
    let mut i : i64 = 0;
    while (i < inserts) {
        seed = (seed * 48271) % 2147483647;
        s.add(seed % keyspace);
        i = i + 1;
    }
    println(s.size());

    let mut checksum : i64 = 0;
    let mut j : i64 = 0;
    while (j < probes) {
        let probe : i64 = (j * 31) % probespace;
        if (s.contains(probe)) {
            checksum = checksum + probe;
        } else {
            checksum = checksum + 1;
        }
        j = j + 1;
    }
    println(checksum);

    let mut seed_rm : i64 = 99999;
    let mut r : i64 = 0;
    while (r < cycles) {
        seed_rm = (seed_rm * 48271) % 2147483647;
        s.remove(seed_rm % keyspace);
        r = r + 1;
    }

    let mut seed_add : i64 = 77777;
    let mut p : i64 = 0;
    while (p < cycles) {
        seed_add = (seed_add * 48271) % 2147483647;
        s.add(seed_add % keyspace);
        p = p + 1;
    }
    println(s.size());
    return 0;
}

strmap_intensive

String-hasher throughput — a hand-rolled open-addressing map (linear probing, cached hashes, 0.75 load factor) implemented identically in all three languages, each using its own native string hasher. Isolates the hasher + probe loop, not a stdlib container.

VariantRunCompileOutput
Run timeRAMCompile timeRAMBinary
C++ -O316 ms46.8 MB833 ms126.1 MB30 KB
C++ -O217 ms46.8 MB822 ms126.3 MB27 KB
C++ -O118 ms46.8 MB746 ms125.8 MB23 KB
Axle -O219 ms46.8 MB196 ms126.0 MB317 KB
Axle -O319 ms46.8 MB202 ms128.2 MB317 KB
Axle -O120 ms46.8 MB148 ms126.1 MB318 KB
Rust -O230 ms46.8 MB208 ms167.8 MB3874 KB
Rust -O131 ms46.8 MB208 ms155.7 MB3873 KB
Rust -O331 ms46.8 MB210 ms167.5 MB3874 KB
Axle -O033 ms46.8 MB89 ms124.2 MB323 KB
C++ -O053 ms46.8 MB609 ms122.5 MB102 KB
Rust -O0107 ms46.8 MB131 ms156.2 MB3910 KB
▸ Source
// String-hasher throughput benchmark.
//
// A hand-rolled open-addressing hash map (`StrMap`) — linear probing,
// cached hashes, a 0.75 load factor and ×2 growth. The point of the bench
// is the hasher and the probe loop, not a container library.
//
// The C++ and Rust siblings implement the SAME map structure, each using
// its own native string hasher (Axle's `hashString`, C++ `std::hash`,
// Rust `DefaultHasher`). So the three measure the hasher + probe over an
// identical layout — never one language's bespoke table against another's
// general-purpose stdlib map.
//
// Workload: 50,000 inserts, then 500,000 lookups, over a 20,000-key
// namespace ("key_0" .. "key_19999"), driven by a Park-Miller LCG. The
// three printed lines (final size, hit count, value checksum) are
// byte-identical across the three languages — the harness cross-checks
// them — because they depend only on which keys and values were stored,
// not on any hasher's probe order.
use std::text::hashing::hashString;
use std::text::StringBuilder;

class StrMap {
    keys   : string[];
    values : i32[];
    hashes : i64[];
    states : i32[];
    cap    : i32;
    len    : i32;
    mask   : i32;

    constructor(initial_cap : i32) {
        let mut c : i32 = initial_cap;
        if (c < 4) { c = 4; }
        let mut p : i32 = 1;
        while (p < c) {
            p = p * 2;
        }
        self.cap = p;
        self.mask = p - 1;
        self.len = 0;
        self.keys = new string[p];
        self.values = new i32[p];
        self.hashes = new i64[p];
        self.states = new i32[p];
        let mut i : i32 = 0;
        while (i < p) {
            self.states[i] = 0;
            i = i + 1;
        }
    }
    fn insertCached(mut self, key : string, value : i32, h : i64) : void {
        let m : i32 = self.mask;
        let mut i : i32 = (h as i32) & m;
        while (true) {
            if (self.states[i] == 0) {
                self.keys[i] = key;
                self.values[i] = value;
                self.hashes[i] = h;
                self.states[i] = 1;
                self.len = self.len + 1;
                return;
            }
            i = (i + 1) & m;
        }
    }
    fn rehashInto(mut self, new_cap : i32) : void {
        let old_cap : i32 = self.cap;
        let old_keys : string[] = self.keys;
        let old_values : i32[] = self.values;
        let old_hashes : i64[] = self.hashes;
        let old_states : i32[] = self.states;
        self.cap = new_cap;
        self.mask = new_cap - 1;
        self.len = 0;
        self.keys = new string[new_cap];
        self.values = new i32[new_cap];
        self.hashes = new i64[new_cap];
        self.states = new i32[new_cap];
        let mut j : i32 = 0;
        while (j < new_cap) {
            self.states[j] = 0;
            j = j + 1;
        }
        let mut r : i32 = 0;
        while (r < old_cap) {
            if (old_states[r] == 1) {
                self.insertCached(old_keys[r], old_values[r], old_hashes[r]);
            }
            r = r + 1;
        }
    }
    pub fn put(mut self, key : string, value : i32) : void {
        if ((self.len * 4) >= (self.cap * 3)) {
            self.rehashInto(self.cap * 2);
        }
        let h : i64 = hashString(key);
        let m : i32 = self.mask;
        let mut i : i32 = (h as i32) & m;
        while (true) {
            let st : i32 = self.states[i];
            if (st == 0) {
                self.keys[i] = key;
                self.values[i] = value;
                self.hashes[i] = h;
                self.states[i] = 1;
                self.len = self.len + 1;
                return;
            }
            if (st == 1) {
                if (self.hashes[i] == h) {
                    if (self.keys[i].equals(key)) {
                        self.values[i] = value;
                        return;
                    }
                }
            }
            i = (i + 1) & m;
        }
    }
    pub fn get(self, key : string) : i32 | null {
        let h : i64 = hashString(key);
        let m : i32 = self.mask;
        let mut i : i32 = (h as i32) & m;
        let mut probed : i32 = 0;
        while (probed < self.cap) {
            let st : i32 = self.states[i];
            if (st == 0) { return null; }
            if (st == 1) {
                if (self.hashes[i] == h) {
                    if (self.keys[i].equals(key)) {
                        return self.values[i];
                    }
                }
            }
            i = (i + 1) & m;
            probed = probed + 1;
        }
        return null;
    }
    fn containsKey(self, key : string) : bool {
        let h : i64 = hashString(key);
        let m : i32 = self.mask;
        let mut i : i32 = (h as i32) & m;
        let mut probed : i32 = 0;
        while (probed < self.cap) {
            let st : i32 = self.states[i];
            if (st == 0) { return false; }
            if (st == 1) {
                if (self.hashes[i] == h) {
                    if (self.keys[i].equals(key)) { return true; }
                }
            }
            i = (i + 1) & m;
            probed = probed + 1;
        }
        return false;
    }
    pub fn size(self) : i32 {
        return self.len;
    }
}

fn main() : void {
    let inserts : i32 = 50000;
    let lookups : i32 = 500000;
    let keyspace : i32 = 20000;

    // Pre-build the keyspace as a `string[N]` array so the
    // inner loop only pays for hash + probe, not the per-iter
    // string-formatting cost.
    let mut pool : string[20000] = string[20000];
    let mut setup : i32 = 0;
    while (setup < keyspace) {
        let sb : StringBuilder = new StringBuilder();
        sb.append("key_").appendI32(setup);
        pool[setup] = sb.toString();
        setup = setup + 1;
    }

    let m : StrMap = new StrMap(16);

    // Park-Miller LCG over i64 so the multiplication doesn't wrap
    // on the first iteration — an i32 state takes one step to flip
    // negative and the modulus then stops covering the keyspace.
    let mut seed : i64 = 12345;
    let mut i : i32 = 0;
    while (i < inserts) {
        seed = (seed * 48271) % 2147483647;
        let key_idx : i32 = (seed % (keyspace as i64)) as i32;
        let value : i32 = (seed % 100000) as i32;
        m.put(pool[key_idx], value);
        i = i + 1;
    }

    // Lookups: half hit the pool (in-range index), half miss
    // (index ≥ keyspace simulated by mod 2*keyspace and reaching
    // for a "key_<huge>" never inserted).
    let mut sum : i64 = 0;
    let mut hits : i32 = 0;
    let mut j : i32 = 0;
    while (j < lookups) {
        let idx : i32 = j % keyspace;
        // Single probe: `get` returns `i32 | null`, smart-cast to `i32`
        // inside the guard — the `if let Some(v) = m.get(&k)` shape, not
        // the `containsKey` + `get` double probe.
        let v : i32 | null = m.get(pool[idx]);
        if (v != null) {
            hits = hits + 1;
            sum = sum + (v as i64);
        }
        j = j + 1;
    }

    println(m.size());
    println(hits);
    println(sum);
}