Hi there!
Some days ago I first time faces with benchmarks in go and did hands-on for my class. If you use Windows + WSL Ubuntu for Golang, my experience would be useful for you.
I faced couple of problems with components, lets talk about
No Graphvis for pprof
I made my first profile
$ go test -bench=BenchmarkGetDomainStat -cpuprofile=cpu -memprofile=mem
$ go tool pprof -http="localhost:8080" cpu
Serving web UI on http://localhost:8080
Failed to execute dot. Is Graphviz installed?
exec: "dot": executable file not found in $PATH
There is no Graphviz. Google it up, we have to install graphviz:
$ sudo apt install graphviz gv
If you get some fails like I:
E: Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/g/ghostscript/ghostscript-x_9.26~dfsg+0-0ubuntu0.18.04.15_amd64.deb 404 Not Found [IP: 91.189.91.38 80]
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
just update and repeat:
$ sudo apt-get update
$ sudo apt install graphviz gv
Whoa! You have your graphviz and pprof ready to show you cool graphs.
No benchstat
I installed Go 1.17.1 and forget about anything. But in case of benchmarks i want to compare two results:
$ benchstat benchmarks/00 benchmarks/01
benchstat: command not found
WTF? there is no benchstat installed by default, lets fix it:
$ go get golang.org/x/perf/cmd/benchstat
go: downloading golang.org/x/perf v0.0.0-20220722155240-3d85ee92886d
go get: added golang.org/x/perf v0.0.0-20220722155240-3d85ee92886d
also go get informs me about deprecating and offers to use 'go install'. Good idea for trying next time
Now lets check result:
$ benchstat benchmarks/00 benchmarks/01
name old time/op new time/op delta
GetDomainStat-8 1.15s ±75% 0.36s ±11% -69.05% (p=0.000 n=10+10)
Cool, benchstat is avaible and my optimizations work well
I hope my googling is helpful and will save few minutes for you, my dear Windows WSL gophers!
Top comments (0)