Compilebench benchmarks the speed of the Go compiler.
It times the compilation of various packages and prints results in the format used by package testing (and expected by rsc.io/benchstat).
The options are:
-alloc Report allocations. -compile exe Use exe as the path to the cmd/compile binary. -compileflags 'list' Pass the space-separated list of flags to the compilation. -count n Run each benchmark n times (default 1). -cpuprofile file Write a CPU profile of the compiler to file. -memprofile file Write a memory profile of the compiler to file. -memprofilerate rate Set runtime.MemProfileRate during compilation. -run regexp Only run benchmarks with names matching regexp.
Although -cpuprofile and -memprofile are intended to write a combined profile for all the executed benchmarks to file, today they write only the profile for the last benchmark executed.
The default memory profiling rate is one profile sample per 512 kB allocated (see “go doc runtime.MemProfileRate”). Lowering the rate (for example, -memprofilerate 64000) produces a more fine-grained and therefore accurate profile, but it also incurs execution cost. For benchmark comparisons, never use timings obtained with a low -memprofilerate option.
Assuming the base version of the compiler has been saved with “toolstash save,” this sequence compares the old and new compiler:
compilebench -count 10 -compile $(toolstash -n compile) >old.txt compilebench -count 10 >new.txt benchstat old.txt new.txt