Skip to main content

Benchmarks

SG's promise is software that is safe and runs as fast as C. These pages are where that is measured: the numbers, how they were taken, and where SG is still slower. A case SG loses is shown as plainly as one it wins (the rules).

The pages​

PageWhat it holds
SG against C61 small programs, each written in SG and in C by hand, on macOS
SG against C on WindowsThe same programs on Windows 11 on Arm
Programs against Rust and Zigwc and grep, written in SG, Rust and Zig
The library against Rust and ZigThe modules of std against Rust's crates and Zig's library: JSON, compression, zip, hashes, checksums, hex and Base64, Unicode, time, random numbers, the log, the network
Slower than C, and could be betterEvery place where SG was found slower, and what would fix it
How it is measuredThe rules of fairness, the machines, the compilers, and how to run it all again

At a glance: against C​

The time of SG divided by the time of the same program in C, both built by the same C compiler with -O2; 1.00 is the same speed. Of 61 programs, 37 are within 5% of C, 13 are faster and 11 are slower (all of them).

ProgramSG / C
Recursive fib(40)0.98
A linked list of a million nodes, built, walked and freed1.01
A list of a million numbers, filled, changed, added up1.02
Three hundred million lookups that give back a borrow or nothing1.01
Counting in a hash table, with a keyed hash against crafted keys1.20
A tree of folders with several owners each (shared checked, weak)1.53
Printing two million structs0.47

At a glance: against Rust and Zig​

Every case of every trial and module, SG's release build against the fastest of Rust and Zig in their release builds; below 1 SG is faster. SG is faster in 8 of the 25 cases, slower in 14. The memory each held, the size of each program, and the builds with checks are on the pages of each.

AreaCaseSGFastest of the othersSG / fastest
wc100 MB0.088 s0.067 s (Rust)1.31
wc100 MB from the input0.088 s0.067 s (Rust)1.31
grep-c ERROR0.046 s0.060 s (Zig)0.77
grep-n timeout0.052 s0.069 s (Zig)0.75
grep-c -i error0.150 s0.069 s (Zig)2.17
grep-c '[a-z]+[0-9]+@example\.com (PUT|DELETE)'0.228 s0.129 s (Zig)1.77
grep'in [0-9]{4} ms: .*日本'0.064 s0.072 s (Zig)0.89
grep-v -c INFO0.049 s0.062 s (Zig)0.79
jsonRecords, read and summed0.476 s0.552 s (Zig)0.86
jsonRecords, read and written back0.688 s0.719 s (Zig)0.96
jsonA document a line, each read and summed0.392 s0.464 s (Zig)0.84
jsonCoordinates, read and summed0.355 s0.415 s (Rust)0.86
compression100 MB of a log, compressed1.616 s0.949 s (Rust, zlib-rs)1.70
compression100 MB of a log, opened0.084 s0.086 s (Rust, zlib-rs)0.98
compression99,640 records, each compressed and opened1.562 s1.551 s (Rust)1.01
compression100 MB that do not compress, compressed1.483 s1.267 s (Rust, zlib-rs)1.17
zip100 MB in 10,001 entries, written1.068 s0.770 s (Rust)1.39
zip10,001 entries, read0.139 s0.183 s (Rust)0.76
zip100,000 entries, listed0.027 s0.008 s (Zig)3.38
hash100 MB of a log, hashed0.049 s0.041 s (Zig)1.20
hash10,000,000 hashes, chained0.331 s0.284 s (Zig)1.17
hash921,952 lines, each signed0.138 s0.113 s (Zig)1.22
checksum100 MB of a log, CRC-320.013 s0.010 s (Rust)1.30
checksum100 MB of a log, Adler-320.024 s0.022 s (Rust)1.09
checksum921,952 lines, each a CRC-320.044 s0.035 s (Rust)1.26

Where the code is​

FolderWhat is in it
interpreter/bench/The programs against C, name.sg and name.c, and run.py, which measures them
trials/The programs and the modules of std in SG, Rust and Zig, and measure.py, which measures them

How to run them again is at the end of How it is measured.