Benchmark the init cost of Go packages
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
testdata/scripts
LICENSE
README.md
go.mod
go.sum
main.go
main_test.go

README.md

benchinit

Benchmark the initialization cost of your packages or programs.

go get -u mvdan.cc/benchinit

This includes the cost of init functions, plus initialising globals. In other words, a package's contribution to the slowness before main is run.

Quickstart

Benchmarking a single package is simple:

benchinit cmd/go

You can also include all dependencies in the benchmark:

benchinit -r cmd/go

Finally, like any other benchmark, you can pass in go test flags:

benchinit -r -count=5 -benchtime=2s cmd/go

Further reading

This tool was result of a discussion with @josharian. You can read more about Josh's idea in his blog post.