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
ArrayList push / get / remove churn with geometric growth.
| Variant | Run | Compile | Output | ||
|---|---|---|---|---|---|
| Run time | RAM | Compile time | RAM | Binary | |
| Axle -O2 | 52 ms | 44.5 MB | 114 ms | 121.5 MB | 309 KB |
| Axle -O3 | 53 ms | 44.5 MB | 116 ms | 125.1 MB | 308 KB |
| C++ -O2 | 66 ms | 44.5 MB | 530 ms | 122.9 MB | 17 KB |
| C++ -O3 | 66 ms | 44.5 MB | 529 ms | 122.8 MB | 17 KB |
| Rust -O2 | 71 ms | 44.5 MB | 116 ms | 146.3 MB | 3864 KB |
| Rust -O3 | 74 ms | 44.5 MB | 117 ms | 144.5 MB | 3864 KB |
| Rust -O1 | 113 ms | 44.5 MB | 107 ms | 147.1 MB | 3864 KB |
| C++ -O1 | 125 ms | 44.5 MB | 522 ms | 122.5 MB | 17 KB |
| Axle -O1 | 141 ms | 44.5 MB | 104 ms | 123.3 MB | 309 KB |
| Axle -O0 | 210 ms | 44.5 MB | 80 ms | 122.3 MB | 310 KB |
| C++ -O0 | 250 ms | 44.5 MB | 502 ms | 118.7 MB | 24 KB |
| Rust -O0 | 372 ms | 44.5 MB | 96 ms | 141.4 MB | 3871 KB |
// 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<i32, i32> insert + lookup churn.
| Variant | Run | Compile | Output | ||
|---|---|---|---|---|---|
| Run time | RAM | Compile time | RAM | Binary | |
| Axle -O3 | 105 ms | 45.5 MB | 157 ms | 127.5 MB | 310 KB |
| Axle -O2 | 110 ms | 45.5 MB | 156 ms | 125.3 MB | 310 KB |
| Axle -O1 | 118 ms | 45.5 MB | 135 ms | 126.1 MB | 310 KB |
| Rust -O3 | 195 ms | 45.5 MB | 178 ms | 162.6 MB | 3884 KB |
| Rust -O2 | 196 ms | 45.5 MB | 165 ms | 165.2 MB | 3883 KB |
| Rust -O1 | 205 ms | 45.5 MB | 162 ms | 164.0 MB | 3883 KB |
| Axle -O0 | 262 ms | 45.5 MB | 89 ms | 126.1 MB | 313 KB |
| C++ -O3 | 418 ms | 45.5 MB | 588 ms | 123.0 MB | 18 KB |
| C++ -O2 | 427 ms | 45.5 MB | 583 ms | 123.2 MB | 18 KB |
| C++ -O1 | 501 ms | 45.5 MB | 571 ms | 122.6 MB | 18 KB |
| C++ -O0 | 1.19 s | 45.5 MB | 540 ms | 119.9 MB | 46 KB |
| Rust -O0 | 1.21 s | 45.5 MB | 119 ms | 155.5 MB | 3920 KB |
// 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;
}Mixed HashMap workload — interleaved insert / erase / rehash stress.
| Variant | Run | Compile | Output | ||
|---|---|---|---|---|---|
| Run time | RAM | Compile time | RAM | Binary | |
| Axle -O2 | 192 ms | 44.1 MB | 194 ms | 125.3 MB | 311 KB |
| Axle -O3 | 196 ms | 44.1 MB | 219 ms | 127.7 MB | 311 KB |
| Axle -O1 | 277 ms | 44.1 MB | 148 ms | 125.9 MB | 311 KB |
| Rust -O3 | 470 ms | 44.1 MB | 192 ms | 161.0 MB | 3885 KB |
| Rust -O2 | 489 ms | 44.1 MB | 191 ms | 162.0 MB | 3884 KB |
| Rust -O1 | 525 ms | 44.1 MB | 176 ms | 163.8 MB | 3884 KB |
| Axle -O0 | 680 ms | 44.1 MB | 94 ms | 127.9 MB | 314 KB |
| C++ -O3 | 1.01 s | 44.1 MB | 653 ms | 123.4 MB | 21 KB |
| C++ -O2 | 1.02 s | 44.1 MB | 627 ms | 123.3 MB | 18 KB |
| C++ -O1 | 1.20 s | 44.1 MB | 606 ms | 123.2 MB | 18 KB |
| C++ -O0 | 4.40 s | 44.1 MB | 551 ms | 120.1 MB | 47 KB |
| Rust -O0 | 6.23 s | 44.1 MB | 127 ms | 158.9 MB | 3922 KB |
// 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 with string keys — hashing + probing over text.
| Variant | Run | Compile | Output | ||
|---|---|---|---|---|---|
| Run time | RAM | Compile time | RAM | Binary | |
| Axle -O2 | 204 ms | 45.6 MB | 198 ms | 128.1 MB | 321 KB |
| Axle -O3 | 204 ms | 45.6 MB | 209 ms | 126.1 MB | 321 KB |
| Axle -O1 | 214 ms | 45.6 MB | 157 ms | 126.2 MB | 321 KB |
| Rust -O3 | 232 ms | 45.6 MB | 213 ms | 169.3 MB | 3888 KB |
| C++ -O1 | 243 ms | 45.6 MB | 712 ms | 125.8 MB | 24 KB |
| C++ -O3 | 245 ms | 45.6 MB | 741 ms | 125.8 MB | 24 KB |
| C++ -O2 | 246 ms | 45.6 MB | 733 ms | 126.3 MB | 24 KB |
| Rust -O2 | 246 ms | 45.6 MB | 213 ms | 170.3 MB | 3887 KB |
| Rust -O1 | 257 ms | 45.6 MB | 196 ms | 169.4 MB | 3888 KB |
| Axle -O0 | 272 ms | 45.6 MB | 95 ms | 126.2 MB | 325 KB |
| C++ -O0 | 499 ms | 45.6 MB | 635 ms | 122.1 MB | 80 KB |
| Rust -O0 | 546 ms | 45.6 MB | 132 ms | 166.9 MB | 3938 KB |
// 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 with string keys, all distinct — every put takes the insert branch and acquires its own copy of the key.
| Variant | Run | Compile | Output | ||
|---|---|---|---|---|---|
| Run time | RAM | Compile time | RAM | Binary | |
| Rust -O3 | 258 ms | 92.0 MB | 210 ms | 171.5 MB | 3888 KB |
| Rust -O2 | 264 ms | 92.1 MB | 207 ms | 168.7 MB | 3887 KB |
| Rust -O1 | 276 ms | 92.1 MB | 194 ms | 169.0 MB | 3888 KB |
| Axle -O3 | 291 ms | 59.8 MB | 205 ms | 126.4 MB | 321 KB |
| C++ -O1 | 294 ms | 54.1 MB | 706 ms | 125.7 MB | 24 KB |
| Axle -O2 | 295 ms | 59.8 MB | 196 ms | 126.1 MB | 321 KB |
| C++ -O3 | 297 ms | 54.1 MB | 730 ms | 126.0 MB | 24 KB |
| C++ -O2 | 300 ms | 54.1 MB | 728 ms | 126.2 MB | 24 KB |
| Axle -O1 | 303 ms | 59.8 MB | 156 ms | 126.1 MB | 321 KB |
| Axle -O0 | 378 ms | 59.8 MB | 94 ms | 126.1 MB | 325 KB |
| C++ -O0 | 602 ms | 54.1 MB | 635 ms | 122.4 MB | 80 KB |
| Rust -O0 | 678 ms | 92.1 MB | 132 ms | 166.4 MB | 3937 KB |
// 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 membership tests and insertion churn.
| Variant | Run | Compile | Output | ||
|---|---|---|---|---|---|
| Run time | RAM | Compile time | RAM | Binary | |
| Axle -O3 | 93 ms | 43.9 MB | 160 ms | 128.2 MB | 310 KB |
| Axle -O1 | 95 ms | 43.9 MB | 132 ms | 127.4 MB | 310 KB |
| Axle -O2 | 95 ms | 43.9 MB | 159 ms | 128.1 MB | 310 KB |
| Rust -O3 | 162 ms | 43.9 MB | 190 ms | 163.1 MB | 3885 KB |
| Rust -O2 | 172 ms | 43.9 MB | 171 ms | 161.1 MB | 3883 KB |
| Rust -O1 | 176 ms | 43.9 MB | 168 ms | 163.7 MB | 3883 KB |
| Axle -O0 | 224 ms | 43.9 MB | 89 ms | 126.0 MB | 313 KB |
| C++ -O3 | 520 ms | 43.9 MB | 601 ms | 123.1 MB | 18 KB |
| C++ -O2 | 527 ms | 43.9 MB | 598 ms | 122.9 MB | 18 KB |
| C++ -O1 | 607 ms | 43.9 MB | 586 ms | 122.6 MB | 18 KB |
| Rust -O0 | 1.40 s | 43.9 MB | 125 ms | 156.1 MB | 3923 KB |
| C++ -O0 | 1.61 s | 43.9 MB | 551 ms | 119.7 MB | 48 KB |
// 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;
}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.
| Variant | Run | Compile | Output | ||
|---|---|---|---|---|---|
| Run time | RAM | Compile time | RAM | Binary | |
| C++ -O3 | 16 ms | 46.8 MB | 833 ms | 126.1 MB | 30 KB |
| C++ -O2 | 17 ms | 46.8 MB | 822 ms | 126.3 MB | 27 KB |
| C++ -O1 | 18 ms | 46.8 MB | 746 ms | 125.8 MB | 23 KB |
| Axle -O2 | 19 ms | 46.8 MB | 196 ms | 126.0 MB | 317 KB |
| Axle -O3 | 19 ms | 46.8 MB | 202 ms | 128.2 MB | 317 KB |
| Axle -O1 | 20 ms | 46.8 MB | 148 ms | 126.1 MB | 318 KB |
| Rust -O2 | 30 ms | 46.8 MB | 208 ms | 167.8 MB | 3874 KB |
| Rust -O1 | 31 ms | 46.8 MB | 208 ms | 155.7 MB | 3873 KB |
| Rust -O3 | 31 ms | 46.8 MB | 210 ms | 167.5 MB | 3874 KB |
| Axle -O0 | 33 ms | 46.8 MB | 89 ms | 124.2 MB | 323 KB |
| C++ -O0 | 53 ms | 46.8 MB | 609 ms | 122.5 MB | 102 KB |
| Rust -O0 | 107 ms | 46.8 MB | 131 ms | 156.2 MB | 3910 KB |
// 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);
}