Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save sangheee/abadfede115c2948136d7503c3a40c9c to your computer and use it in GitHub Desktop.
Save sangheee/abadfede115c2948136d7503c3a40c9c to your computer and use it in GitHub Desktop.
Go cpu and memory profiling benchmarks. #golang #benchmark
FILENAME=$(basename $(pwd))
go test -run=^$ -bench=. -cpuprofile=cpu.out -benchmem -memprofile=mem.out
go tool pprof -pdf $FILENAME.test cpu.out > cpu.pdf && open cpu.pdf
go tool pprof -pdf --alloc_space $FILENAME.test mem.out > alloc_space.pdf && open alloc_space.pdf
go tool pprof -pdf --alloc_objects $FILENAME.test mem.out > alloc_objects.pdf && open alloc_objects.pdf
go tool pprof -pdf --inuse_space $FILENAME.test mem.out > inuse_space.pdf && open inuse_space.pdf
go tool pprof -pdf --inuse_objects $FILENAME.test mem.out > inuse_objects.pdf && open inuse_objects.pdf
go-torch $FILENAME.test cpu.out -f $FILENAME.svg && open $FILENAME.svg
rm alloc_space.pdf alloc_objects.pdf inuse_space.pdf inuse_objects.pdf cpu.out mem.out $FILENAME.test torch.svg $FILENAME.svg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment