Benchmarks

Strings benchmarks

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

Benchmarks for v0.23.0

Strings

append

StringBuilder append throughput — building one large string.

VariantRunCompileOutput
Run timeRAMCompile timeRAMBinary
Rust -O25 ms44.8 MB102 ms146.9 MB3863 KB
Rust -O35 ms44.8 MB102 ms144.8 MB3863 KB
Rust -O16 ms44.8 MB95 ms142.3 MB3863 KB
Axle -O17 ms44.8 MB78 ms121.4 MB306 KB
Axle -O27 ms44.8 MB84 ms124.6 MB306 KB
Axle -O37 ms44.8 MB84 ms123.3 MB306 KB
Axle -O012 ms44.8 MB74 ms125.4 MB306 KB
C++ -O112 ms44.8 MB447 ms120.5 MB17 KB
C++ -O212 ms44.8 MB454 ms120.7 MB17 KB
C++ -O312 ms44.8 MB457 ms120.9 MB17 KB
Rust -O035 ms44.8 MB89 ms143.8 MB3869 KB
C++ -O051 ms44.8 MB431 ms116.9 MB30 KB
▸ Source
// EXPECTED_EXIT: 0
// StringBuilder benchmark #1 — raw append throughput.
// Shared logic with append.cpp / append.rs
// (run via `axle bench --compare cpp,rust`).
//
// Workload: append a fixed 16-byte ASCII chunk 1,000,000 times,
// building a 16 MB buffer (~20 capacity-doubling reallocations).
// Output: total length + 3 sampled bytes (start / middle / end) so
// the three languages cross-check byte-identically without an
// O(n^2) full-string walk.
use std::text::StringBuilder;

fn main() : i32 {
    let n : i64 = 1000000;
    let chunk : string = "abcdefghijklmnop"; // 16 ASCII bytes

    let sb : StringBuilder = new StringBuilder();
    let mut i : i64 = 0;
    while (i < n) {
        sb.append(chunk);
        i = i + 1;
    }

    // O(1) byte length as the cross-impl correctness signal (the
    // workload is deterministic, so identical length ⇒ identical
    // bytes). Reading individual bytes back via `byteAt` would be
    // O(n) per call (AxleString carries no length → `strlen`), which
    // would measure the string ABI, not the builder.
    println(sb.byteLength());
    sb.dispose();
    return 0;
}

churn

StringBuilder grow / reset churn across many small builders.

VariantRunCompileOutput
Run timeRAMCompile timeRAMBinary
Axle -O18 ms45.1 MB87 ms127.6 MB315 KB
Rust -O29 ms45.1 MB109 ms145.1 MB3863 KB
Rust -O39 ms45.1 MB108 ms147.0 MB3863 KB
Axle -O310 ms45.1 MB97 ms124.2 MB315 KB
Axle -O211 ms45.1 MB95 ms125.4 MB315 KB
Rust -O111 ms45.1 MB101 ms147.5 MB3863 KB
C++ -O121 ms45.1 MB459 ms120.5 MB17 KB
C++ -O221 ms45.1 MB461 ms120.7 MB17 KB
C++ -O325 ms45.1 MB457 ms120.8 MB17 KB
Axle -O029 ms45.1 MB82 ms126.2 MB316 KB
Rust -O0138 ms45.1 MB92 ms142.0 MB3870 KB
C++ -O0192 ms45.1 MB437 ms117.1 MB32 KB
▸ Source
// EXPECTED_EXIT: 0
// StringBuilder benchmark #3 — build / materialize / reset churn.
// Shared logic with churn.cpp / churn.rs (run via `axle bench --compare cpp,rust`).
//
// Workload: 200,000 outer rounds; each appends a 3-byte chunk 20
// times, materialises the result to a `string` (one alloc + copy),
// reads its first byte into an accumulator (so the build can't be
// optimised away), then clear()s for reuse. Stresses the
// append + toString + clear hot loop with buffer reuse. Output:
// the accumulated first-byte sum.
use std::text::StringBuilder;

fn main() : i32 {
    let outer : i64 = 200000;
    let inner : i64 = 20;
    let chunk : string = "xyz";

    let sb : StringBuilder = new StringBuilder();
    let mut acc : i64 = 0;
    let mut o : i64 = 0;
    while (o < outer) {
        let mut k : i64 = 0;
        while (k < inner) {
            sb.append(chunk);
            k = k + 1;
        }
        let s : string = sb.toString();
        acc = acc + (s.byteAt(0) as i64);
        sb.clear();
        o = o + 1;
    }

    println(acc);
    sb.dispose();
    return 0;
}

int_format

Integer-to-string formatting via StringBuilder.

VariantRunCompileOutput
Run timeRAMCompile timeRAMBinary
Axle -O28 ms45.9 MB97 ms123.4 MB306 KB
Axle -O38 ms45.9 MB98 ms123.0 MB306 KB
Axle -O19 ms45.9 MB83 ms123.5 MB306 KB
C++ -O19 ms45.9 MB467 ms120.6 MB17 KB
C++ -O29 ms45.9 MB469 ms121.0 MB17 KB
C++ -O39 ms45.9 MB472 ms120.9 MB17 KB
Rust -O215 ms45.9 MB114 ms146.0 MB3864 KB
Rust -O315 ms45.9 MB114 ms147.8 MB3863 KB
Rust -O118 ms45.9 MB103 ms148.7 MB3863 KB
Axle -O019 ms45.9 MB74 ms125.4 MB307 KB
Rust -O059 ms45.9 MB93 ms144.1 MB3874 KB
C++ -O091 ms45.9 MB436 ms117.4 MB30 KB
▸ Source
// EXPECTED_EXIT: 0
// StringBuilder benchmark #2 — integer formatting throughput.
// Shared logic with int_format.cpp / int_format.rs
// (run via `axle bench --compare cpp,rust`).
//
// Workload: append 500,000 LCG-driven integers (each formatted to
// decimal) separated by commas — a CSV-style builder. Stresses
// `appendI64` (int→string conversion + bulk append) plus the
// comma separator append. Output: total length + first / last byte.
//
// Caveat: `appendI64` writes the digits straight into the builder, where the
// siblings' `std::to_string` / `to_string()` materialise a temporary per
// integer. An API difference, not a language-speed one — read this bench for
// Axle's formatter, not as a like-for-like ratio.
use std::text::StringBuilder;

fn main() : i32 {
    let n : i64 = 500000;
    let sb : StringBuilder = new StringBuilder();

    let mut seed : i64 = 12345;
    let mut i : i64 = 0;
    while (i < n) {
        seed = (seed * 48271) % 2147483647;
        sb.appendI64(seed % 100000);
        sb.append(",");
        i = i + 1;
    }

    // O(1) byte length as the cross-impl correctness signal (same
    // LCG + same integer formatting ⇒ identical bytes ⇒ identical
    // length). See append.axle for why per-byte readback is avoided.
    println(sb.byteLength());
    sb.dispose();
    return 0;
}