The benchmark suite
adam bench: Adam's speed beside C, measured on your own machine.
What it measures
The benchmark suite ships in res/bench: one program, bench.adam, over fourteen kernels in res/bench/kernels, each with a C twin in res/bench/c that computes the same checksum. adam bench builds and times it from an unzipped release with nothing else installed. A kernel whose checksum differs from its C twin's fails the run, so every level is seen doing the same work as C.
The kernels: fib (recursive calls), sieve (indexed stores over a bool array), sort (quicksort over a var array), matmul (a float64 matrix multiply), nbody (float64 with sqrt and division), strings (concatenation and IntToStr), cvt (int64 to float64 and division), spill and pressure (values live across calls: the register allocator), alloc (ref-counted binary trees), collections (List and Map), closures, generics (one generic heap for two types) and parallel (for parallel, Concurrency).
Running it
adam bench every kernel, all four levels, the host's triple
adam bench fib sort -opt fast two kernels at one level
adam bench -t x86_64-windows-gnu,x86_64-linux-gnu both triples (Linux through WSL on Windows)
-opt and -t take comma lists (Building, Targets). The benchmark program is built by the running adam through the same build as adam build, once per level and triple, and the build's time and the exe's size are kept beside the times. Each kernel runs in its own process, Adam's and C's alike: three processes of five timed runs after one warmup; a process prints its best run, and the least of those is the kernel's time. Time it on a quiet machine: another job running beside it shows up in the numbers.
A kernel's time is shown as its ratio to its C twin's (Adam / C): up to 1.10 is graded good, up to 1.50 near, above that far. The console prints a table per triple while it runs.
The results and the report
The run writes bench-<triple>.json into -o's folder (default: output beside adam): the adam version, the triple, the machine (CPU, threads, OS, memory), each level's build time and exe size, and each kernel's times, C's time and checks. Beside it goes one self-contained HTML5 report for the whole run (bench-<triple>.html, or bench.html for several triples; --report <file> names it), with each level's geometric mean over the kernels as its headline.
The report's look is a template read at run time: res/bench/report/template.html and template-howto.html, the same page with every tag and value explained for writing your own. --template <file> uses yours. --render <file,...> makes the report again from saved results alone, with no build and no timing, so a template can be tuned in seconds. The template engine is the std unit System.TextTemplate (The reference).
Checking for regressions
adam bench --check --baseline <file,...> compares a run with earlier results, each triple with the file for it, and fails a kernel whose ratio at a level grew by more than 10%. It judges the ratio, not the time, so a baseline from another machine still compares. Adam's own pipeline runs it on both triples before every release.
The C side
The C twins ship prebuilt per triple (res/bench/c/bin/<triple>/bench_c), built with clang -O2. res/bench/c/build.cmd (Windows) and build.sh (Linux) rebuild them with your own clang on PATH, to check the C numbers with a compiler of your own; running the suite never needs it.
Timing your own code
System.Bench is the timing the suite uses, for any Adam program. BenchRun(name, kernel, runs) times a ref func(): int64 (Closures): one untimed warmup, then the fastest of the timed runs on the high-resolution clock. The kernel returns a checksum of its work, so no optimization level can drop the work; BenchLine writes a result as <name> us=<microseconds> check=<checksum>.
module exe bench_run;
import System.Bench;
// The sum of 1 .. ALimit, the long way
func SumTo(const ALimit: int64): int64;
var
LSum: int64;
LI: int64;
begin
LSum := 0;
for LI := 1 to ALimit do
LSum := LSum + LI;
end;
return LSum;
end;
var
GResult: BenchResult;
begin
GResult := BenchRun("sum", func(): int64
begin
return SumTo(1000000);
end, 3);
println("{} check={} runs={} stable={}", GResult.Name, GResult.Check, GResult.Runs, GResult.Stable);
end.
sum check=500000500000 runs=3 stable=true
Every routine and field: The reference.