Benchmarks
Twenty-five small programs, each written with the same algorithm and the same input in Tomato and in Go, Rust, C, C++, Java, C#, Swift, JavaScript, TypeScript, PHP and Python. Tick the languages to show below. Every version prints the same checksum, so none of the work can be skipped.
Loading the results…
These numbers were measured on a MacBook Pro with an Apple M3 Pro chip (arm64, macOS). The earlier numbers on this page (v0.51, ten benchmarks) came from an Apple M1 Mac, and the Linux x86-64 run of the same suite (a 64-core Threadripper) is in the repository under benchmarks/results/linux-x86_64/; the three sets are not comparable.
Summary
Time per benchmark
Median wall-clock seconds of the runs; bars are drawn on one scale per benchmark, so a shorter bar is faster. The number is the median time in seconds.
Table
Tomato's time ÷ each language's time
Tomato's median time divided by the other language's median time, per benchmark: below 1.0 Tomato is faster (highlighted), above 1.0 it is slower.
Build time, binary size and memory
Method
- Same work. Each language implements the same loop-for-loop algorithm (no tricks such as caching that only one language could use) and prints a checksum.
benchmarks/run.shcompares every version's output with the Tomato version's: the smoke run that the test suite makes fails on any difference, and a full run prints a warning and records"agrees": falsein the JSON. - Builds. Every number below used the command shown here. Tomato is built by this repository's own compiler twice: in release mode (no leak checks, one-line errors with no call trace) and in debug mode (leak checks and full error text), and each is shown separately. Go, Rust, C, C++, C# and Swift use their usual optimized builds, Java runs on the HotSpot virtual machine, JavaScript and TypeScript on Node (TypeScript with its types stripped, so it runs as the same JavaScript), and PHP and Python are the interpreters as installed. A language whose tools were not installed when the suite ran has no box.
- Runs. Each program runs 10 times (Python and PHP too). The runs of every benchmark and language are shuffled into one random order with a fixed, recorded seed, rather than run back to back, so thermal throttling and background load fall evenly on every row. The table shows the median, the fastest run and the spread (slowest minus fastest, over the median); every time is in benchmarks.json. Time is the wall clock of the whole process (including start-up: a few milliseconds for the compiled programs, and tens of milliseconds for Java, C# and Node), and memory is the peak resident size.
- Not tuned. The programs are written the way a beginner in each language would write them: lists, strings and dicts from the standard library, objects as separate heap allocations (a
Boxin Rust, a pointer in Go). Nobody hand-tuned any version.
Caveats
- One laptop, one run of the suite (about 35 minutes), fixed inputs. The Mac was running on battery power, had been restarted a few minutes before the run started (its load average was still 18 then, and 3 to 7 while the programs ran), and was not otherwise idle, so some timings varied between runs. Small differences may be noise; the load averages are above, and the spread is in the table and JSON.
- Node, PHP and .NET were not installed on that Mac, so the run used Node 26.13.1 and PHP 8.6.0 from conda-forge packages and the .NET 10.0.404 SDK from Microsoft's installer, each in a private folder. Go, Rust, Python, Java and Swift are the Mac's own installs; the versions are above.
- Tomato is young and its compiler does little optimization of its own (release mode relies on clang and link-time inlining of the runtime). The numbers are a snapshot of this version, not a verdict on the language.
- Tomato's
intis unlimited in size, with small values held in one tagged word; Go, Rust and (for big values) Python pay different costs for numbers, so the integer benchmarks compare designs as much as compilers. The Gointand Rustu64versions can overflow silently or stop; the checksums are chosen not to. - The sort benchmark compares different algorithms: Tomato's
sortedis a radix sort for long lists of ints and floats and an introsort for the rest (up to v0.51 an introsort for all of them), C uses the library'sqsort, C++std::sort, Rust uses the standard library'ssort(a stable merge sort), and Go itssortpackage. A Rust radix sort (benchmarks/sort/sort_radix.rs) is measured too and shown under the sort chart. - Every language uses its usual fast library for big integers:
math/bigin Go, the built-inintin Python, and thenum-bigintcrate in Rust (whose standard library has none), built withcargo build --release;benchmarks/bigint/Cargo.lockpins the crate versions. Java usesBigInteger, C#System.Numerics, and JavaScript and TypeScriptBigInt. C, C++, Swift and PHP have none in their standard libraries, so those versions multiply an array of words by hand, which is not a general big-integer library. C has no hash table either, so its wordcount carries a small one. Tomato uses its own built-inint. - The mandelbrot checks use explicit float conversions in Go so that no fused multiply-add changes a result.
- Rust and Go may inline or remove work a language without a heavy optimizer cannot; the checksums prevent removing it entirely, but loops can still be unrolled and vectorized.
What the numbers suggest for Tomato
The list is in docs/performance.md.
- Investigate numeric loops, including spectral_norm and nbody, with profiling and less-loaded runs before drawing conclusions.
- Investigate allocations in text code:
splitstill makes one string per piece. Profiling and less-loaded runs can help identify the costs. - Investigate allocation-heavy code: binary_trees (2.4× Rust, 3.9× Go) and kmers (2.8× Rust) are the largest gaps in this run.
Since v0.48 release mode links the program and the runtime with link-time optimisation and the cycle collector skips objects that cannot form cycles; since v0.49 the compiler no longer counts references for reads of a variable that keeps its value alive, sorted is a native introsort and big integers are freed; since v0.50 small objects come from a size-class allocator, string paths work in place, range(a, b, step) loops are counted loops and sorted takes key= and cmp= functions.
Source
Everything is in the benchmarks/ folder: one folder per benchmark with its programs, sizes.txt (the inputs), run.sh (the runner), measure.c (the timing helper) and results/ (the numbers on this page). Run benchmarks/run.sh yourself; it needs clang and skips every other language whose tools are missing. The other languages' programs exist only as a comparison; Tomato's own tooling uses no Python.