Skip to content

Instantly share code, notes, and snippets.

@arsham
Last active November 20, 2023 03:42
Show Gist options
  • Save arsham/bbc93990d8e5c9b54128a3d88901ab90 to your computer and use it in GitHub Desktop.
Save arsham/bbc93990d8e5c9b54128a3d88901ab90 to your computer and use it in GitHub Desktop.
Go cpu and memory profiling benchmarks. #golang #benchmark
go test -run=. -bench=. -benchtime=5s -count 5 -benchmem -cpuprofile=cpu.out -memprofile=mem.out -trace=trace.out ./package | tee bench.txt
go tool pprof -http :8080 cpu.out
go tool pprof -http :8081 mem.out
go tool trace trace.out
go tool pprof $FILENAME.test cpu.out
# (pprof) list <func name>
# go get -u golang.org/x/perf/cmd/benchstat
benchstat bench.txt
rm cpu.out mem.out trace.out *.test
@ptflp
Copy link

ptflp commented Jul 24, 2021

how to use?

@arsham
Copy link
Author

arsham commented Jul 26, 2021

You can run the instructions line by line.

@bernardolm
Copy link

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment