MoxyMoxy

Benchmarks

The same five programs (and two of them again with gates) in C, Moxy, Rust and Zig, with the same algorithm, sizes and output (the runner fails if any two outputs differ). Numbers are the median of 21 runs after one warm-up run, wall-clock including process start-up; RSS is peak resident memory from /usr/bin/time. Lower is better everywhere. "vs C" is the ratio to the C version.

This page is generated by bun bench/run.ts --langs moxy,c,rust,zig --runs 21 --page. The prose after the tables is bench/commentary.md.

Machine

model MacBookPro18,2
CPU Apple M1 Max, 10 cores
memory 64 GB
OS macOS 27.2.1
date 2026-12-02
load when run up 14 days, 8:08, 1 user, load averages: 4.61 7.39 10.04

Toolchains and flags

language version build
C Apple clang version 21.0.0 (clang-2100.3.34.2) cc -O2 -std=c11 main.c -lm
Moxy moxy 0.4.0 moxy build main.mxy --release (generates C, then cc)
Rust rustc 1.98.1 (48a229cea 2026-09-01) rustc -C opt-level=3 main.rs
Zig zig 0.14.0 zig build-exe -O ReleaseFast -lc main.zig with -target aarch64-macos.15.0

Moxy's --release build runs the C compiler with the same cc as the C column. The Rust and Zig versions are what a competent user of each language writes: Rust uses Box, Vec and HashMap with no unsafe; Zig picks its allocator per program (stated under each table). None of the versions use SIMD intrinsics, threads or hand-tuned allocators. Target CPU is the compiler default for all four (no -march=native).

$ bun bench/run.ts --langs moxy,c,rust,zig --runs 21 --pagetime vs C, lower is better

binarytrees

C1.00x the time of C

Moxy1.17x the time of C

Rust1.15x the time of C

Zig1.40x the time of C

nbody

C1.00x the time of C

Moxy1.37x the time of C

Rust0.85x the time of C

Zig0.55x the time of C

wordcount

C1.00x the time of C

Moxy1.16x the time of C

Rust0.76x the time of C

Zig0.52x the time of C

jsonroundtrip

C1.00x the time of C

Moxy1.22x the time of C

Rust0.60x the time of C

Zig0.36x the time of C

listchurn

C1.00x the time of C

Moxy1.41x the time of C

Rust1.12x the time of C

Zig1.31x the time of C

binarytreesgate

C1.00x the time of C

Moxy1.60x the time of C

jsonroundtripgate

C1.00x the time of C

Moxy2.17x the time of C

The hairline is C (1.0x). Apple M1 Max, 10 cores, macOS 27.2.1, 2026-12-02. The machine was under load (load averages 4.61 7.39 10.04), so the ratios are the useful part.

Results

binarytrees

Allocate and walk many short-lived complete binary trees, depth 16. Allocation: C calloc/free per node; Rust Box; Zig std.heap.c_allocator with an explicit drop; Moxy ref struct (reference counted).

Sources: C, Moxy, Rust, Zig.

language time (ms) vs C peak RSS (MB) vs C
C 130 1.00x 5.8 1.00x
Moxy 152 1.17x 9.8 1.70x
Rust 149 1.15x 5.9 1.03x
Zig 181 1.40x 5.8 1.01x

nbody

Five bodies, 5,000,000 steps of a symplectic integrator. No allocation in C, Rust and Zig; Moxy keeps the bodies in a global list.

Sources: C, Moxy, Rust, Zig.

language time (ms) vs C peak RSS (MB) vs C
C 249 1.00x 1.7 1.00x
Moxy 340 1.37x 1.8 1.02x
Rust 211 0.85x 1.9 1.10x
Zig 137 0.55x 1.7 0.99x

wordcount

Build a 500,000 word text, split it, count with a hash table. C: a hand-written open-addressing table. Rust: HashMap<&str, i64> (SipHash). Zig: std.StringHashMap (Wyhash) on c_allocator. Moxy: map[string, int].

Sources: C, Moxy, Rust, Zig.

language time (ms) vs C peak RSS (MB) vs C
C 38.4 1.00x 5.8 1.00x
Moxy 44.6 1.16x 26.9 4.60x
Rust 29.0 0.76x 6.4 1.10x
Zig 20.0 0.52x 6.3 1.09x

jsonroundtrip

Hand-written JSON writer and parser, 40 round trips of a 2,000 record document. C: malloc per node. Rust: an enum of owned String and Vec. Zig: one ArenaAllocator per tree, freed in a single call, which is what Zig code usually does for a tree with one lifetime and is cheaper than the per-node frees in the other versions. Moxy: ref struct nodes.

Sources: C, Moxy, Rust, Zig.

language time (ms) vs C peak RSS (MB) vs C
C 97.1 1.00x 5.4 1.00x
Moxy 118 1.22x 9.9 1.83x
Rust 58.1 0.60x 6.2 1.15x
Zig 35.4 0.36x 6.0 1.12x

listchurn

Build, reverse, sum and drop a 10,000 node singly linked list, 400 times. C and Zig: one malloc and free per node. Rust: Option<Box<Node>> with an iterative drop. Moxy: ref struct nodes.

Sources: C, Moxy, Rust, Zig.

language time (ms) vs C peak RSS (MB) vs C
C 70.2 1.00x 1.9 1.00x
Moxy 98.7 1.41x 2.1 1.11x
Rust 78.7 1.12x 2.0 1.07x
Zig 92.1 1.31x 1.9 1.02x

binarytreesgate

binarytrees with each short-lived tree inside gate { }, against C with a bump arena reset per tree instead of calloc/free.

Sources: C, Moxy.

language time (ms) vs C peak RSS (MB) vs C
C 30.6 1.00x 7.7 1.00x
Moxy 49.1 1.60x 13.8 1.79x

jsonroundtripgate

jsonroundtrip with each round inside gate { }, against C with a bump arena per round. The output pieces go into a global list, outside every gate, so each is copied to the heap.

Sources: C, Moxy.

language time (ms) vs C peak RSS (MB) vs C
C 43.8 1.00x 4.9 1.00x
Moxy 95.0 2.17x 12.2 2.49x

selfcompile (Moxy only)

moxy emit src/main.mxy, the compiler compiling its own source to C: 106 ms, 106.0 MB peak RSS. There is no C, Rust or Zig version of the compiler, so this is not compared; it is tracked against the 100 ms budget in the roadmap.

What the numbers say

The machine was not idle for this run (load averages between 4.6 and 6.6 on 10 cores, against 13 to 17.5 for the previous page), so absolute times carry some noise and the ratios between languages are the useful part.

These numbers are for 0.4.0. Against the 0.3.1-era page, wordcount went from 2.43x C to 1.16x and jsonroundtrip from 1.90x to 1.22x: number formatting no longer goes through printf, string building concatenates in one allocation, split and map upsert stopped copying. The other three moved within the noise.

Where Moxy loses. Moxy is slower than C on every benchmark here, and slower than Rust and Zig on most. The summary is "within about 1.2x of C on allocation and string work, about 1.4x on tight loops over lists".

  • nbody (1.37x C). No allocation in the loop; the cost left is the language's. Moxy list indexing is bounds-checked and the program keeps its bodies in a global list, so every field access goes through the list, where C, Rust and Zig use a fixed array of structs the optimizer keeps in registers. Rust and Zig finishing ahead of C is a compiler effect on this loop, not a different algorithm; I did not isolate which optimization.
  • listchurn (1.41x C). One 16 byte header and a count per node. Rust (1.12x) and Zig (1.31x) are closer to C. Peak memory is within 11% of C.
  • wordcount memory (4.6x C). Time is close now, memory is not: every word is still its own heap string with a header, where C, Rust and Zig borrow slices of one buffer. A borrowed string view is the fix.
  • Gates. A gate is slower than C's hand-written bump arena: 1.60x on binarytrees and 2.17x on jsonroundtrip, with 1.8x and 2.5x the memory. Inside a gate the counts still run (only the per-object free and the drop walk are skipped), stores are checked so nothing in the gate escapes, and in jsonroundtrip every output piece is copied out to the heap. C does none of that. The gate rows are against C's arena code, not against plain Moxy: the plain binarytrees (152 ms) is slower than the gate version (49 ms).

Where Moxy is close.

  • binarytrees (1.17x C, Rust 1.15x, Zig 1.40x). Allocation heavy; the 16 byte header keeps peak memory at 1.7x C (9.8 MB against 5.8 MB).
  • wordcount and jsonroundtrip time (1.16x and 1.22x). Rust and Zig are well ahead of C on both (0.36x to 0.76x): better hash maps and borrowed strings, and for jsonroundtrip Zig's arena per tree.
  • Peak memory is within 11% of C on nbody and listchurn.

What this page does not measure. Compile time (Moxy's --release build is Moxy to C to cc, so it costs more than cc alone), binary size (see make budget), and anything multi-threaded. The Zig times are for -O ReleaseFast, which removes safety checks; Rust's opt-level=3 keeps bounds checks on, and Moxy list and string indexing are bounds-checked (its --release build drops the debug integer overflow checks). Those are the defaults a user gets, not a like-for-like safety level.

The regression gate. CI compares Moxy to C only (bench/baseline.json, 5% limit). Rust and Zig are for this page and are not gated.

Edit this page on GitHub