neo vs Zig · language

neo vs Zig.

The same input and the same kernels, in neo's C++ and in Zig. Across 5 measurements neo finished 1.47× faster in the middle and 1.88× at most; Zig was not quicker on any.

01 · The race

One kernel at a time

Each piece of work below has its own race, what it measures, how each side does it, the code that ran and every number taken for it. In a race both ships run for the same stretch: Zig completes the work once, and neo completes it as many times as the measured ratio says, turning around at each end.

  1. 01.1 · load the CSV, parse and type1.47×
  2. 01.2 · filter amount > 500, count1.88×
  3. 01.3 · sort, as a permutation1.42×
  4. 01.4 · sort into a new table1.51×
  5. 01.5 · sum by region1.40×

01.1 · kernel · 1,000,000 rows

load the CSV, parse and type

neo 3.59 ms · Zig 5.28 ms · 1.47× neo. Against every engine →

neo

Zig

0 runs

0 runs

What this measures

Read a 46 MB CSV of a million rows and six columns into a table: split the bytes into fields, parse the amount column into numbers, and dictionary-encode the region column. Each engine's typed read, best of two, with the first read of a fresh process kept separately.

How neo does it

neo's parser finds the structural characters with SIMD, splits the file into blocks and parses them on every core above a megabyte, with results identical to the serial path. Typing and the dictionary happen once, at load, on the pool, so no kernel after it touches text. In the ledger's breakdown that is 2.8 ms of parse, 0.2 ms of typing and about nothing for the dictionary.

How Zig does it

The port's load is the whole program rather than one function, so it is not excerpted here: neon-cpp/bench/lang/zig/main.zig.

neo's side: the call and the contract

the harness, calling the engine · neon-cpp/bench/bench_engine_options.cpp:194
l.t = csv::parse(raw);
the parser's contract · neon-cpp/core/csv.h:55
Table parse(std::string_view raw);  // parallel above 1 MB, serial below; identical results

Every number taken for it

measurementneoZig× neo
time, msThree loads to warm, then three timed whole loads; the median over every timed load of seven shuffled rounds.3.595.281.47×

Read it with this

  • A port builds one dictionary where neo builds three.
  • Taken on a shared machine. Both columns ran in the same shuffled rounds, so the multiple stands, but the times themselves read high.

01.2 · kernel · 1,000,000 rows

filter amount > 500, count

neo 0.017 ms · Zig 0.032 ms · 1.88× neo. Against every engine →

neo

Zig

0 runs

0 runs

What this measures

Count the rows whose amount is over 500: a million comparisons on a typed column, the answer one integer. Each library's count is written the way its users write it.

How neo does it

neo's filter produces a bitmap: one bit per row, 125 KB for a million rows, written at memory speed, with indices made only when something needs them. Below about a million values it runs on one thread, above that on the pool. The contract is the JavaScript node's: NaN never matches.

How Zig does it

Two passes on the pool. Each chunk counts its hits, a running total gives every chunk its own slice of the output, and each chunk then writes its row numbers into that slice.

filter amount > 500 · neon-cpp/bench/lang/zig/main.zig:1140
fn filterMulti(pool: *Pool, amount: []const f64, out: []u32, counts: []usize, bases: []usize) usize {
    const nk = counts.len;
    var j: FilterJob = .{ .amount = amount, .out = out, .counts = counts, .bases = bases };
    pool.runChunks(&j, FilterJob.countJob, nk);
    var sum: usize = 0;
    for (0..nk) |k| {
        bases[k] = sum;
        sum += counts[k];
    }
    pool.runChunks(&j, FilterJob.writeJob, nk);
    return sum;
}

neo's side: the call and the contract

the harness, calling the engine · neon-cpp/bench/bench_engine_options.cpp:337
const double f5 = timeIt([&] { Bitmap b = compareDoubles(amt.data(), n, Cmp::Gt, 500, &pool); sink = b.words[0]; }, 7);
the filter's contract · neon-cpp/core/selection.h:1
// selection.h — the result of a filter: one bit per row. 1M rows = 125 KB,
// written at memory speed; indices are produced only when something needs them.

struct Bitmap {
    std::vector<uint64_t> words;
    size_t bits = 0;
    bool test(size_t i) const { return (words[i >> 6] >> (i & 63)) & 1; }
    size_t count() const;
    std::vector<uint32_t> indices() const;  // ascending row indices of the set bits
};

// JS measurefilter semantics: NaN never matches. Sequential below ~1M values; the pool otherwise.
Bitmap compareDoubles(const double* v, size_t n, Cmp op, double threshold, Pool* pool);

Every number taken for it

measurementneoZig× neo
time, msBest of three in one process, then the median over seven rounds, every engine run once a round in a shuffled order.0.0170.0321.88×

Read it with this

  • The two results differ in form: neo's figure is for a bitmap, the port's for a list of row numbers.
  • Taken on a shared machine. Both columns ran in the same shuffled rounds, so the multiple stands, but the times themselves read high.

01.3 · kernel · 1,000,000 rows

sort, as a permutation

neo 1.04 ms · Zig 1.48 ms · 1.42× neo. Against every engine →

neo

Zig

0 runs

0 runs

What this measures

Produce the stable ascending order of the amount column as a permutation of row indices, without moving any other column. SQL engines have no such form, so DuckDB and Spark sit this one out.

How neo does it

neo turns each double into a sortable 64-bit key and runs an LSD radix sort on the pool: O(n), stable, with the JavaScript rule that NaN sorts as negative infinity and ties keep their order. The ledger's design levers show the step from std::stable_sort at 84 ms, to radix at 14 ms, to the pool at 1 ms.

How Zig does it

A parallel radix sort: a pass over the keys first, then for each digit a histogram for every chunk, write positions from a running total, and a scatter on the pool.

sort, as a permutation · neon-cpp/bench/lang/zig/main.zig:1315 · show all 53 lines
fn sortMulti(pool: *Pool, amount: []const f64, perm: []u32, bufs: *SortBufs, hist: []u32, pos: []u32, uniq: []i32) void {
    const nk = hist.len / NB;
    var j: PSort = .{
        .amount = amount,
        .n = amount.len,
        .keys = bufs.keys,
        .hist = hist,
        .pos = pos,
        .uniq = uniq,
        .pass = 0,
        .src_keys = bufs.keys[0],
        .dst_keys = bufs.keys[1],
        .src_idx = null,
        .dst_idx = perm,
    };
    pool.runChunks(&j, PSort.prepassJob, nk);
    var active: [NP]bool = undefined;
    var nactive: usize = 0;
    for (0..NP) |p| {
        const first_u = uniq[p];
        var same = first_u >= 0;
        for (1..nk) |k| same = same and uniq[k * NP + p] == first_u;
        active[p] = !same;
        nactive += @intFromBool(active[p]);
    }
    if (nactive == 0) {
        for (perm, 0..) |*x, k| x.* = @intCast(k);
        return;
    }
    j.dst_idx = if (nactive % 2 == 1) perm else bufs.idx_tmp;
    var other_idx: []u32 = if (nactive % 2 == 1) bufs.idx_tmp else perm;
    var first = true;
    for (0..NP) |p| {
        if (!active[p]) continue;
        j.pass = p;
        if (!first) pool.runChunks(&j, PSort.histJob, nk); // pass-0 histogram came from the pre-pass
        first = false;
        var running: u32 = 0;
        for (0..NB) |d| {
            for (0..nk) |k| {
                pos[k * NB + d] = running;
                running += hist[k * NB + d];
            }
        }
        pool.runChunks(&j, PSort.scatterJob, nk);
        const tk = j.src_keys;
        j.src_keys = j.dst_keys;
        j.dst_keys = @constCast(tk);
        j.src_idx = j.dst_idx;
        j.dst_idx = other_idx;
        other_idx = @constCast(j.src_idx.?);
    }
}

neo's side: the call and the contract

the harness, calling the engine · neon-cpp/bench/bench_engine_options.cpp:372
const double s4 = timeIt([&] { sortIndexByDouble(amt.data(), n, perm, &pool); sink = perm[0]; }, 3);
the sort's contract · neon-cpp/core/sort.h:1
// sort.h — stable O(n) sorting of row indices by a double key (parallel radix).
// JS numeric sort semantics: NaN sorts as -Infinity; ties keep input order.

// Fills `idx` with the stable ascending order of keys[0..n). pool may be null.
void sortIndexByDouble(const double* keys, size_t n, std::vector<uint32_t>& idx, Pool* pool);

Every number taken for it

measurementneoZig× neo
time, msBest of three in one process, then the median over seven rounds, every engine run once a round in a shuffled order.1.041.481.42×

Read it with this

  • Taken on a shared machine. Both columns ran in the same shuffled rounds, so the multiple stands, but the times themselves read high.

01.4 · kernel · 1,000,000 rows

sort into a new table

neo 2.88 ms · Zig 4.37 ms · 1.51× neo. Against every engine →

neo

Zig

0 runs

0 runs

What this measures

Sort by amount and build the whole sorted table, every column reordered.

How neo does it

The permutation from the radix sort drives a parallel gather of every column, with the dictionary column moved as ids. The ledger times the gather alone at under three milliseconds for a million rows.

How Zig does it

Every column is gathered through the permutation on the pool, into a fresh arena of bytes and a fresh array of offsets.

sort into a new table · neon-cpp/bench/lang/zig/main.zig:1469
fn materializeMulti(pool: *Pool, t: *const Table, perm: []const u32, m: *Mat, scratch: [][MAX_COLS]usize, ends: [][MAX_COLS]usize) void {
    const nk = scratch.len;
    var j: MatJob = .{ .t = t, .perm = perm, .m = m, .nk = nk, .bytes = scratch, .ends = ends };
    pool.runChunks(&j, MatJob.sizeJob, t.ncols * nk);
    var run: [MAX_COLS]usize = @splat(0);
    for (0..nk) |k| {
        for (0..t.ncols) |c| {
            const b = j.bytes[k][c];
            j.bytes[k][c] = run[c];
            run[c] += b;
            j.ends[k][c] = run[c];
        }
    }
    for (0..t.ncols) |c| m.cols[c].offsets[0] = 0;
    pool.runChunks(&j, MatJob.copyJob, (t.ncols + 1) * nk); // the extra column of items gathers the typed arrays
    for (0..t.ncols) |c| m.cols[c].len = run[c];
}

neo's side: the call and the contract

the sort's contract · neon-cpp/core/sort.h:1
// sort.h — stable O(n) sorting of row indices by a double key (parallel radix).
// JS numeric sort semantics: NaN sorts as -Infinity; ties keep input order.

// Fills `idx` with the stable ascending order of keys[0..n). pool may be null.
void sortIndexByDouble(const double* keys, size_t n, std::vector<uint32_t>& idx, Pool* pool);

Every number taken for it

measurementneoZig× neo
time, msBest of three in one process, then the median over seven rounds, every engine run once a round in a shuffled order.2.884.371.51×

Read it with this

  • Taken on a shared machine. Both columns ran in the same shuffled rounds, so the multiple stands, but the times themselves read high.

01.5 · kernel · 1,000,000 rows

sum by region

neo 0.020 ms · Zig 0.028 ms · 1.40× neo. Against every engine →

neo

Zig

0 runs

0 runs

What this measures

Total the amount column for each of five regions: a grouped sum, the kernel every dashboard runs.

How neo does it

The region column was dictionary-encoded at load, so its ids are the group numbers and no string is hashed. The sum is taken on the pool in any order only when the column is whole numbers small enough that no addition can round; otherwise it is added in row order on one thread, because a floating-point sum depends on its order, and the contract is the JavaScript loop's result to the bit.

How Zig does it

Each chunk of rows adds into its own small array of group totals on the pool, and the chunks' totals are then added together in a fixed order.

sum by region · neon-cpp/bench/lang/zig/main.zig:1515
fn aggMulti(pool: *Pool, amount: []const f64, ids: []const u32, ngroups: usize, partial: [][MAX_GROUPS]f64, out: []f64) void {
    const nk = partial.len;
    var j: AggJob = .{ .amount = amount, .ids = ids, .ngroups = ngroups, .partial = partial };
    pool.runChunks(&j, AggJob.run, nk);
    for (0..ngroups) |g| {
        var s: f64 = 0;
        for (0..nk) |k| s += partial[k][g]; // fixed chunk order -> deterministic sums
        out[g] = s;
    }
}

neo's side: the call and the contract

the harness, calling the engine · neon-cpp/bench/bench_engine_options.cpp:454
const double a5 = G <= 16 ? timeIt([&] { groupSumAnyOrder(amtP, idP, n, G, &pool, pairTotal); sink = static_cast<size_t>(pairTotal[0]); }, 9) : 0;
the group sum's contract · neon-cpp/core/groupsum.h:1
// groupsum.h — a typed column's sum, count and extremes per group: what the aggregate node's measures need
// once the column is doubles (toDoubles) and every row has a group number.
//
// The results are the ones a loop over the rows in order gives — `if (isFinite(v)) { sum += v; n++;
// if (v < min) min = v; if (v > max) max = v; }` a group, which is what the JavaScript does — to the bit:
//   • counts and extremes are taken a part of the rows at a time on the pool and the parts joined in row
//     order (a strict comparison keeps the earlier of two equal values, as the loop does);
//   • a sum is added in row order on one thread, because a floating-point sum depends on its order —
//     unless the column is whole numbers small enough that no addition can round (wholeNumbers below),
//     where every order gives the same bits and the rows are summed on the pool, two a step.
// bench/bench_agg_node.cpp times each path against the node and checks it; PHD.md §30.

// The sum alone, any order, two rows a step; for tests and the benchmark (groupStats calls it when it may).
// False, and nothing written, when there are more groups than it is built for.
bool groupSumAnyOrder(const double* x, const uint32_t* id, size_t n, size_t groups, Pool* pool, double* sums);

Every number taken for it

measurementneoZig× neo
time, msBest of three in one process, then the median over seven rounds, every engine run once a round in a shuffled order.0.0200.0281.40×

Read it with this

  • Taken on a shared machine. Both columns ran in the same shuffled rounds, so the multiple stands, but the times themselves read high.

02 · Every number

The same kernels, in other languages

1,000,000 rows · ms, lower is better · 2026-10-12 06:38 · shared machine

kernelneoZig× neo
load (parse + type + dictionary)3.595.281.47×
filter amount > 5000.0170.0321.88×
sort, as a permutation1.041.481.42×
sort into a new table2.884.371.51×
sum by region0.0200.0281.40×

The kernels were ported to Go, Rust, Swift and Zig, each told to beat the C++; what they did better was then taken into the C++. Milliseconds, 1,000,000 rows. Where a port is still ahead, it is shown ahead. These are the million-row figures of the study in the next card, the same record: A round runs every engine once, in an order shuffled each round, and a figure is the median over the rounds (7 at 1,000,000 rows, 5 at 10,000,000 and 3 at 100,000,000). The load is one loop in every binary: three loads first, then three timed whole loads, the previous result still alive during each; its figure is the median over every timed load of every round. Filter, sort and sum are each binary's best of three in a process, and the figure the median of those. Threads: a port is run on 16 and 18 (every core) and its figure for a kernel is the better of the two; neo runs as it ships, on sixteen, and on every core for a load of 256 MB and more. Before a time is taken every engine prints its table as one number, an FNV over every cell, and after it its checks; the line under the table says whether they agreed. What still differs: a port is a benchmark kernel written for this comparison, not a library; each is built as its own run.sh builds it — the Rust and Zig ports for this processor, the Rust port with link-time optimisation, the Swift port with its checks off — and neo at -O3 with none of that; a port builds one dictionary where neo builds three; neo's filter figure is a bitmap where a port's is a list of row numbers; and the file is one synthetic shape (six columns, no field over sixteen bytes).

03 · The code that ran

Zig's side, in full

Zig is a small systems language with manual memory management, no hidden control flow and a reputation for tight binaries. The port runs on every core. The port was written to beat the C++ and given the C++ numbers to beat. Its code is beside each race above, and nothing of it is left out here.

neo's side: the calls and the contracts

neo's kernels are the product, so their bodies stay in the engine. What is published is what a reader needs to judge the comparison: the harness calling the engine, and each kernel's declaration with the guarantees it is held to, down to the order a floating-point sum is taken in. Each contract is beside its race above; the harness lines together, and whatever no race showed, are here. The binaries run on request, and the scripts named below reproduce every number on this page.

the harness, calling the engine · neon-cpp/bench/bench_engine_options.cpp
 194  l.t = csv::parse(raw);
 337  const double f5 = timeIt([&] { Bitmap b = compareDoubles(amt.data(), n, Cmp::Gt, 500, &pool); sink = b.words[0]; }, 7);
 372  const double s4 = timeIt([&] { sortIndexByDouble(amt.data(), n, perm, &pool); sink = perm[0]; }, 3);
 454  const double a5 = G <= 16 ? timeIt([&] { groupSumAnyOrder(amtP, idP, n, G, &pool, pairTotal); sink = static_cast<size_t>(pairTotal[0]); }, 9) : 0;
how energy is read · neon-cpp/bench/energy.h:1
// energy.h — what a process has used, as the operating system's own ledger has it: the energy it was billed,
// its processor time, the wake-ups it caused. The one reader of that ledger, for two questions:
//   what a kernel costs — the Evals page's Energy view (bench_engine_options.cpp reads it around each kernel;
//     tools/energy/energy.cpp checks the counter and reads it for a command it runs;
//     bench/lang/python/yardstick.py reads the same field; PHD.md section 33)
//   what a process costs at rest — the idle studies (scripts/idle_cost.sh and scripts/idle_server.py take
//     `neon_energy --pid <pid>` twice and subtract; PHD.md section 31.1)
//
// macOS on Apple silicon: proc_pid_rusage(RUSAGE_INFO_V6). ri_energy_nj — nanojoules billed to the process's
// threads for the processor cores they ran on, since it started. Not the memory, the disk or the screen, and
// not the machine at rest: what running this code added. (Not ri_billed_energy: against half a second of a
// busy loop that field read 0.08 mJ where ri_energy_nj read 1,887.) Beside it, processor time in nanoseconds
// — `ps` has hundredths of a second, more than a resting window uses in a minute — and the wake-ups. No
// privilege is needed, and any process of the same user can be read, so a tree of processes can be summed.
// Linux: /proc/<pid>/stat and /proc/<pid>/status — clock ticks and context switches. No energy: RAPL is one
// figure for the whole machine and root's to read.
// Elsewhere: nothing is read (ok stays false).
//
// A reading is cumulative; a measurement is the difference of two. The counter moves in steps (a thread's
// share is settled when it leaves a core or enters the kernel), so a window should be a quarter of a second
// or more: `neon_energy --check` prints how far apart the steps are on the machine it runs on.

04 · Diligence

What both sides were held to

Scripts: scripts/scale_study.sh · measured 2026-10-12 · the numbers on this page come from the same ledger as the app's own Evals page, written by neon-cpp/scripts/results_md.py.

More comparisons