blob: 48ea7203a40a1d835f564df7214c4ecc09752b0c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
---
title: "Go Benchmarking"
tags: posts
---
1. write a benchmark
2. run a benchmark
3. get a profile
4. optimise
5. run your tests
6. goto 2.
## cpuprofile
`go test -test=XXX -bench <regex> -cpuprofile <file>`
## memprofile
`go test -test=XXX -bench <regex> -memprofile <file> -benchmem`
## pprof
[pprof usage](https://github.com/google/pprof/blob/main/doc/README.md)
`go pprof -http=:8080 profile.pb.gz`
will show a web UI for analysing the profile.
### views:
- flame graph: `localhost:8080/ui/flamegraph`
- shows percentage breakdown of how much resource each "call" made.
- clicking a box will make it "100%" allowing for deep diving
- right click "show source code" to view
- top: `localhost:8080/ui/top`
- shows top functions
- `flat`: profile samples in this function
- `cum`: (cumulative) profile samples in this function and its callees
- source: `localhost:8080/ui/source`
- each source line is annotated with the time spent in that source line
- the first number does not count time spent in functions called from the source line
- the second number does
|