2 programs measured with axle bench: dijkstra_heap, graph_bfs_hashset. Run time, peak RAM at compile and run, and binary size, with the exact source for each language.
Benchmarks for v0.23.0
Dijkstra over a 500k-node / 3M-edge weighted digraph with a binary min-heap hand-rolled on each language's own growable list — deliberately NOT std::priority_queue vs BinaryHeap, which would compare two different sift algorithms. Same lazy-stale-skip rule, same packed (distance, node) key, same logical-size heap that never calls a tail-removal the others lack.
| Variant | Run | Compile | Output | ||
|---|---|---|---|---|---|
| Run time | RAM | Compile time | RAM | Binary | |
| Axle -O3 | 302 ms | 45.5 MB | 156 ms | 123.3 MB | 310 KB |
| C++ -O3 | 302 ms | 45.5 MB | 314 ms | 110.6 MB | 16 KB |
| C++ -O2 | 303 ms | 45.5 MB | 310 ms | 110.5 MB | 16 KB |
| Axle -O2 | 311 ms | 45.5 MB | 154 ms | 125.4 MB | 310 KB |
| Rust -O3 | 320 ms | 45.5 MB | 148 ms | 146.4 MB | 3866 KB |
| C++ -O1 | 322 ms | 45.5 MB | 297 ms | 109.8 MB | 17 KB |
| Rust -O2 | 330 ms | 45.5 MB | 153 ms | 146.4 MB | 3866 KB |
| Axle -O1 | 337 ms | 45.5 MB | 124 ms | 125.3 MB | 310 KB |
| Rust -O1 | 342 ms | 45.5 MB | 142 ms | 146.0 MB | 3867 KB |
| Axle -O0 | 754 ms | 45.5 MB | 87 ms | 123.3 MB | 313 KB |
| C++ -O0 | 886 ms | 45.5 MB | 261 ms | 105.9 MB | 36 KB |
| Rust -O0 | 1.13 s | 45.5 MB | 103 ms | 143.3 MB | 3882 KB |
// Dijkstra's shortest paths over a weighted sparse digraph, with a binary
// min-heap built by hand on top of an ArrayList — the routing kernel of
// every map, network planner and build scheduler.
//
// The graph is generated twice from the same LCG (pass 1 counts
// out-degrees, pass 2 scatters targets and weights into CSR arrays), so no
// edge list is materialised. Weights are 1..100.
//
// The priority queue is deliberately NOT each language's stdlib heap: a
// `std::priority_queue` and Axle's ArrayList would then be running
// different sift code. Instead all three implement the same textbook
// binary heap — sift-up on push, swap-root-with-last then sift-down on
// pop — over their own growable list type, so the comparison is the list's
// element access and growth, not two different heap algorithms. Stale
// entries are dropped lazily (`d > dist[node]` → skip), which is what
// makes a heap-based Dijkstra practical without a decrease-key.
//
// The heap carries its own logical size and never shrinks the underlying
// list: a pop overwrites the root and drops the count, and a push reuses a
// retired slot before it appends. All three languages do exactly that — no
// language gets to call a tail-removal the others lack.
//
// The heap entry packs distance above node id (`d * 2^20 + node`), so one
// i64 compare orders the queue identically everywhere.
//
// Two lines are printed: how many nodes were settled, and the sum of their
// final distances.
//
// Equivalent to dijkstra_heap.{cpp,rs} — same graph, same heap, same
// lazy-skip rule, same two printed lines.
use std::collections::ArrayList;
// Store `value` at logical slot `size` and sift it up. The slot is reused
// when a previous pop retired it, appended otherwise. The caller owns the
// logical size and increments it.
fn heap_push(mut h : ArrayList<i64>, size : i64, value : i64) : void ! IndexOutOfBoundsException {
if (size < h.size()) {
h.set(size, value);
} else {
h.add(value);
}
let mut i : i64 = size;
while (i > 0) {
let parent : i64 = (i - 1) / 2;
let pv : i64 = h.get(parent) ?? 0;
let cv : i64 = h.get(i) ?? 0;
if (pv <= cv) {
break;
}
h.set(parent, cv);
h.set(i, pv);
i = parent;
}
}
// Return the minimum of a heap of logical length `size`, having moved the
// last element into the root and sifted it down over the remaining
// `size - 1` slots. The caller owns the logical size and decrements it.
fn heap_pop(mut h : ArrayList<i64>, size : i64) : i64 ! IndexOutOfBoundsException {
let top : i64 = h.get(0) ?? 0;
let n : i64 = size - 1;
let last : i64 = h.get(n) ?? 0;
if (n > 0) {
h.set(0, last);
let mut i : i64 = 0;
while (true) {
let l : i64 = 2 * i + 1;
if (l >= n) {
break;
}
let mut smallest : i64 = l;
let r : i64 = l + 1;
if (r < n && (h.get(r) ?? 0) < (h.get(l) ?? 0)) {
smallest = r;
}
let sv : i64 = h.get(smallest) ?? 0;
let cv : i64 = h.get(i) ?? 0;
if (cv <= sv) {
break;
}
h.set(i, sv);
h.set(smallest, cv);
i = smallest;
}
}
return top;
}
fn main() : i32 ! IndexOutOfBoundsException {
let N : i64 = 500000;
let M : i64 = 3000000;
let SHIFT : i64 = 1048576;
let INF : i64 = 1000000000000000000;
// Pass 1 — out-degrees.
let mut off : i32[500001] = i32[500001];
let mut seed : i64 = 24681357;
let mut e : i64 = 0;
while (e < M) {
seed = (seed * 48271) % 2147483647;
let u : i64 = seed % N;
seed = (seed * 48271) % 2147483647;
seed = (seed * 48271) % 2147483647;
off[u + 1] = off[u + 1] + 1;
e = e + 1;
}
let mut i : i64 = 0;
while (i < N) {
off[i + 1] = off[i + 1] + off[i];
i = i + 1;
}
// Pass 2 — replay the LCG, scatter targets and weights.
let mut cursor : i32[500000] = i32[500000];
let mut adj : i32[3000000] = i32[3000000];
let mut wgt : i32[3000000] = i32[3000000];
seed = 24681357;
e = 0;
while (e < M) {
seed = (seed * 48271) % 2147483647;
let u : i64 = seed % N;
seed = (seed * 48271) % 2147483647;
let v : i64 = seed % N;
seed = (seed * 48271) % 2147483647;
let w : i64 = 1 + seed % 100;
let slot : i64 = (off[u] as i64) + (cursor[u] as i64);
adj[slot] = v as i32;
wgt[slot] = w as i32;
cursor[u] = cursor[u] + 1;
e = e + 1;
}
let mut dist : i64[500000] = i64[500000];
let mut d : i64 = 0;
while (d < N) {
dist[d] = INF;
d = d + 1;
}
let heap : ArrayList<i64> = new ArrayList<i64>();
let mut hsize : i64 = 0;
dist[0] = 0;
heap_push(heap, hsize, 0);
hsize = hsize + 1;
let mut settled : i64 = 0;
while (hsize > 0) {
let packed : i64 = heap_pop(heap, hsize);
hsize = hsize - 1;
let node : i64 = packed % SHIFT;
let dcur : i64 = packed / SHIFT;
if (dcur > dist[node]) {
// A shorter route to `node` was already settled — stale entry.
continue;
}
settled = settled + 1;
let start : i64 = off[node] as i64;
let end : i64 = off[node + 1] as i64;
let mut k : i64 = start;
while (k < end) {
let v : i64 = adj[k] as i64;
let nd : i64 = dcur + (wgt[k] as i64);
if (nd < dist[v]) {
dist[v] = nd;
heap_push(heap, hsize, nd * SHIFT + v);
hsize = hsize + 1;
}
k = k + 1;
}
}
let mut total : i64 = 0;
let mut n : i64 = 0;
while (n < N) {
if (dist[n] < INF) {
total = total + dist[n];
}
n = n + 1;
}
println(settled);
println(total);
return 0;
}Breadth-first search over a 1M-node / 3M-edge sparse digraph, frontier in a growable list and visited set in a hash set. The graph is replayed from one LCG (count degrees, then scatter into CSR) instead of being stored twice, and the BFS depth rides inside the queue entry so the hash set is the only visited bookkeeping — two set probes per discovered neighbour, everywhere.
| Variant | Run | Compile | Output | ||
|---|---|---|---|---|---|
| Run time | RAM | Compile time | RAM | Binary | |
| Axle -O1 | 239 ms | 56.7 MB | 161 ms | 127.6 MB | 313 KB |
| Axle -O3 | 242 ms | 56.6 MB | 193 ms | 128.0 MB | 313 KB |
| Axle -O2 | 244 ms | 56.7 MB | 192 ms | 125.3 MB | 313 KB |
| Rust -O3 | 375 ms | 55.8 MB | 199 ms | 164.8 MB | 3886 KB |
| Rust -O2 | 390 ms | 55.9 MB | 188 ms | 165.8 MB | 3885 KB |
| Rust -O1 | 391 ms | 55.9 MB | 177 ms | 167.8 MB | 3885 KB |
| Axle -O0 | 496 ms | 56.9 MB | 100 ms | 125.8 MB | 317 KB |
| C++ -O3 | 545 ms | 69.1 MB | 437 ms | 116.1 MB | 18 KB |
| C++ -O2 | 551 ms | 69.1 MB | 433 ms | 116.2 MB | 18 KB |
| C++ -O1 | 600 ms | 69.1 MB | 415 ms | 115.8 MB | 18 KB |
| C++ -O0 | 1.64 s | 69.1 MB | 364 ms | 111.9 MB | 66 KB |
| Rust -O0 | 1.78 s | 55.9 MB | 120 ms | 161.5 MB | 3930 KB |
// Breadth-first search over a large sparse digraph, with the frontier in
// an ArrayList and the visited set in a HashSet — the reachability query
// behind dependency resolvers, crawlers and "who can see this" checks.
//
// The graph is generated, never stored twice: the SAME LCG runs over the
// edge list once to count out-degrees and a second time to scatter the
// targets into a CSR array. That is the standard memory-lean CSR build,
// and it keeps the working set at (N + M) i32 slots instead of holding an
// edge-pair list.
//
// The BFS itself carries the depth inside the queue entry — the frontier
// stores `depth * 2^20 + node`, so there is no side distance array and the
// HashSet is genuinely the only visited bookkeeping. Each discovered
// neighbour costs exactly two set probes (one `contains`, one `add`) in
// every language.
//
// Two lines are printed: how many nodes are reachable from node 0, and the
// sum of their BFS depths.
//
// Fair-play notes: same N, same M, same LCG and edge order, same CSR
// layout, same two-probe discovery, and each language uses its own stdlib
// hash set (Axle's HashSet, `std::unordered_set`, Rust's `HashSet`) — the
// hasher is part of what is being compared.
//
// Equivalent to graph_bfs_hashset.{cpp,rs}.
use std::collections::{ArrayList, HashSet};
fn main() : i32 {
let N : i64 = 1000000;
let M : i64 = 3000000;
let SHIFT : i64 = 1048576;
// Pass 1 — out-degree of every node.
let mut off : i32[1000001] = i32[1000001];
let mut seed : i64 = 987654321;
let mut e : i64 = 0;
while (e < M) {
seed = (seed * 48271) % 2147483647;
let u : i64 = seed % N;
seed = (seed * 48271) % 2147483647;
off[u + 1] = off[u + 1] + 1;
e = e + 1;
}
// Prefix sum — off[v] is now where v's targets begin.
let mut i : i64 = 0;
while (i < N) {
off[i + 1] = off[i + 1] + off[i];
i = i + 1;
}
// Pass 2 — replay the same LCG and scatter the targets.
let mut cursor : i32[1000000] = i32[1000000];
let mut adj : i32[3000000] = i32[3000000];
seed = 987654321;
e = 0;
while (e < M) {
seed = (seed * 48271) % 2147483647;
let u : i64 = seed % N;
seed = (seed * 48271) % 2147483647;
let v : i64 = seed % N;
let slot : i64 = (off[u] as i64) + (cursor[u] as i64);
adj[slot] = v as i32;
cursor[u] = cursor[u] + 1;
e = e + 1;
}
// BFS from node 0. The queue entry packs the depth above the node id.
let visited : HashSet<i64> = new HashSet<i64>();
let queue : ArrayList<i64> = new ArrayList<i64>();
visited.add(0);
queue.add(0);
let mut depth_sum : i64 = 0;
let mut head : i64 = 0;
while (head < queue.size()) {
let packed : i64 = queue.get(head) ?? 0;
head = head + 1;
let node : i64 = packed % SHIFT;
let depth : i64 = packed / SHIFT;
depth_sum = depth_sum + depth;
let start : i64 = off[node] as i64;
let end : i64 = off[node + 1] as i64;
let mut k : i64 = start;
while (k < end) {
let nb : i64 = adj[k] as i64;
if (!visited.contains(nb)) {
visited.add(nb);
queue.add((depth + 1) * SHIFT + nb);
}
k = k + 1;
}
}
println(visited.size());
println(depth_sum);
return 0;
}