Benchmarks

Sorting benchmarks

1 programs measured with axle bench: sort_int. Run time, peak RAM at compile and run, and binary size, with the exact source for each language.

Benchmarks for v0.23.0

Sorting

sort_int

Sort 2M i64 with an LSD radix sort in all three languages — Axle's stdlib ArrayList.sort() against a hand-rolled matching radix in C++ and Rust (8-bit digits, byte-skipping on the data's range). Same algorithm, so the number is a language-speed reading.

VariantRunCompileOutput
Run timeRAMCompile timeRAMBinary
Axle -O326 ms44.8 MB134 ms123.2 MB309 KB
Axle -O227 ms44.8 MB138 ms123.4 MB310 KB
C++ -O227 ms44.8 MB283 ms109.9 MB16 KB
C++ -O328 ms44.8 MB286 ms109.9 MB16 KB
Rust -O228 ms44.8 MB135 ms153.3 MB3864 KB
Rust -O328 ms44.8 MB134 ms151.9 MB3864 KB
Axle -O129 ms44.8 MB103 ms125.3 MB309 KB
Rust -O129 ms44.8 MB127 ms151.7 MB3864 KB
C++ -O130 ms44.8 MB274 ms109.2 MB17 KB
Axle -O063 ms44.8 MB80 ms123.4 MB310 KB
C++ -O092 ms44.8 MB253 ms105.6 MB30 KB
Rust -O0123 ms44.8 MB103 ms147.5 MB3878 KB
▸ Source
// EXPECTED_EXIT: 0
// Sort 2,000,000 i64 drawn from a shared MINSTD LCG, then print a checksum
// (full sum + the min / median / max of the sorted array). The C++ and Rust
// siblings generate the SAME data from the same seed and print the same four
// lines, so the harness cross-checks correctness.
//
// `ArrayList<i64>.sort()` dispatches on the element type at compile time
// (see `crates/5-stdlib/axle_stdlib/axle/collections/arraylist.axle`, "Sort the
// elements..."): for `i64` that is an O(n) LSD radix sort, 8-bit digits,
// skipping any byte that never varies across the key set. The C++ and Rust
// siblings hand-roll the same LSD radix sort — same digit width, same
// byte-skip via the data's max value — so all three measure the identical
// algorithm.
use std::collections::ArrayList;

fn main() : i32 {
    let n : i64 = 2000000;
    let l : ArrayList<i64> = new ArrayList<i64>();
    l.reserve(n); // pre-size the buffer, mirroring C++ `reserve` / Rust `with_capacity`
    let mut seed : i64 = 12345;
    let mut i : i64 = 0;
    while (i < n) {
        seed = (seed * 48271) % 2147483647;
        l.add(seed % 1000000);
        i = i + 1;
    }
    l.sort();
    let mut sum : i64 = 0;
    i = 0;
    while (i < n) {
        sum = sum + (l.get(i) ?? 0);
        i = i + 1;
    }
    println(sum);
    println(l.get(0) ?? 0);
    println(l.get(n / 2) ?? 0);
    println(l.get(n - 1) ?? 0);
    return 0;
}