DEV Community

Mikhail Rumpel
Mikhail Rumpel

Posted on

1

First usage golang benchmarks in Ubuntu WSL

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

Enter fullscreen mode Exit fullscreen mode

There is no Graphviz. Google it up, we have to install graphviz:

$ sudo apt install graphviz gv
Enter fullscreen mode Exit fullscreen mode

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?
Enter fullscreen mode Exit fullscreen mode

just update and repeat:

$ sudo apt-get update
$ sudo apt install graphviz gv
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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)
Enter fullscreen mode Exit fullscreen mode

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!

Image of Datadog

Master Mobile Monitoring for iOS Apps

Monitor your app’s health with real-time insights into crash-free rates, start times, and more. Optimize performance and prevent user churn by addressing critical issues like app hangs, and ANRs. Learn how to keep your iOS app running smoothly across all devices by downloading this eBook.

Get The eBook

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay