Hello,
I've written a command line tool
benchls in the same vein as
benchstat that fits a least squares model to parameterized benchmark output.
The basic idea is to take benchmarks like this:
PASS
BenchmarkSort10-4 1000000 1008 ns/op
BenchmarkSort100-4 200000 8224 ns/op
BenchmarkSort1000-4 10000 152945 ns/op
BenchmarkSort10000-4 1000 1950999 ns/op
BenchmarkSort100000-4 50 25081946 ns/op
BenchmarkSort1000000-4 5 302228845 ns/op
BenchmarkSort10000000-4 1 3631295293 ns/op
BenchmarkStableSort10-4 1000000 1260 ns/op
BenchmarkStableSort100-4 100000 16730 ns/op
BenchmarkStableSort1000-4 5000 362024 ns/op
BenchmarkStableSort10000-4 300 5731738 ns/op
BenchmarkStableSort100000-4 20 88171712 ns/op
BenchmarkStableSort1000000-4 1 1205361782 ns/op
BenchmarkStableSort10000000-4 1 14349613704 ns/op
ok github.com/jonlawlor/benchls 138.860s
Where the 10, 100, 1000, ... indicate a number of unsorted elements, and the ns/op indicate the approximate amount of time it took to sort, and then fit a least squares model to describe the relationship between the number of elements and how long it takes:
$ benchls -vars="/?(?P<N>\\d+)-\\d+$" -xtransform="math.Log(N) * N, 1.0" bench.txt
group \ Y ~ math.Log(N) * N 1.0 R^2
BenchmarkSort 2.254e+01±6.4e-02 -2e+06±3.9e+06 0.9999949426719544
BenchmarkStableSort 8.906e+01±1.8e-01 -7e+06±1.1e+07 0.9999973642760738
Where each row indicates the least squares estimate of the performance, parameterized by N * log(N). Here we can see (for illustration only) that sort.Sort is about 4x faster than sort.Stable for large N.
You can put any expression involving only float64's, +, -, *, /, and functions from the math library into both the explanatory and response, and you can identify input variables using named regexp, so functions of multiple variables are possible.
Currently it only reports the model parameters, 95% confidence intervals, and the R^2, but if anyone wants additional goodness of fit stats I can add them. The code is partially derived from (and inspired by) benchstat.
Feedback is appreciated!