Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Capture a CPU profile while Go is doing representative work, inspect hot functions and call paths with go tool pprof, then repeat the same workload to check whether a change helped. A CPU profile shows time spent actively consuming CPU cycles; it does not explain time spent sleeping or waiting for network I/O or synchronization.
Choose a capture method
Use the route that can reproduce the CPU-heavy work you need to understand. Keep the workload representative: a profile reflects the activity captured, not every possible use of the program.
| Route | Best fit | Capture |
|---|---|---|
| Benchmark or test | A repeatable operation you can run under a Go benchmark. | go test -cpuprofile cpu.prof -bench . |
| HTTP service | A running service whose workload can be exercised during capture. | go tool pprof http://localhost:6060/debug/pprof/profile?seconds=30 |
| Standalone program | A program where you can add explicit start and stop calls around the workload. | runtime/pprof.StartCPUProfile and runtime/pprof.StopCPUProfile |
Capture a benchmark or test profile
When a benchmark can reproduce the expensive operation, save a CPU profile as part of the test run:
go test -cpuprofile cpu.prof -bench .
The command writes the profile to cpu.prof. This gives you a repeatable basis for inspecting the benchmark’s CPU use and comparing later runs. Go’s performance guide documents test profiling flags and inspection options.
#1 Best Overall
Capture a running HTTP service
Import net/http/pprof—commonly as a blank import—to register the profiling handlers, and ensure they are available on the HTTP mux your service uses. The handler family is under /debug/pprof/; the CPU profile endpoint is /debug/pprof/profile.
-
Expose the handler on a listener appropriate to your deployment and access-control requirements. Go’s local example uses a listener bound to localhost; do not expose profiling endpoints more broadly than intended.
-
Request a capture for a chosen duration using the
seconds=Nquery parameter. The documented default is 30 seconds. -
For a 30-second local capture, run:
go tool pprof http://localhost:6060/debug/pprof/profile?seconds=30
The profiling request remains occupied until the capture finishes. As of Go 1.22, the handlers require GET requests. See the net/http/pprof documentation and handler source for endpoint behavior.
Capture from a standalone program
For a program that is neither a benchmark nor an HTTP service, write the profile to a file and bracket the work you want to measure with the runtime profiling API:
f, err := os.Create("cpu.prof")
if err != nil {
return err
}
if err := pprof.StartCPUProfile(f); err != nil {
f.Close()
return err
}
// Run the representative CPU-heavy workload here.
pprof.StopCPUProfile()
if err := f.Close(); err != nil {
return err
}
This example assumes the imports for os and runtime/pprof are present and that the surrounding function can return an error. Stop profiling before closing the file; the output is streamed during capture. StartCPUProfile reports an error if CPU profiling is already enabled. The runtime/pprof documentation and package source documentation describe the API.
Inspect hot functions and call paths
Open a saved profile with go tool pprof. Include the program binary when needed for symbol resolution:
go tool pprof cpu.prof
# When needed to resolve symbols:
go tool pprof ./your-program cpu.prof
Start with aggregate function cost to find where CPU time accumulates, then use source and call-path views to understand what code contributes to that cost. The Go diagnostics guide describes top-call listings, graph visualization, weblist, and flame graphs.
PC Slower Than It Used to Be?
A free scan shows the junk files, broken settings and background clutter dragging Windows down - then fixes them in one click.Free scan · Windows 10 & 11Crashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minute-
Hot functions: use the text output to identify functions with substantial CPU cost.
-
Source lines: use list or source-oriented output, such as
weblist, to inspect the relevant implementation. -
Call paths: use graph or flame-graph views to see which callers lead into expensive work and how the cost is distributed.
These views answer different questions: an expensive function is a starting point, while its callers and source lines help explain why it is expensive. The Go diagnostics documentation and the Go Blog’s Profiling Go Programs explain the available views.
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Best Value
Verify an optimization with a comparable run
After changing code, capture another profile under equivalent inputs and conditions. Use the same benchmark or service workload and compare the same kinds of pprof output. Otherwise, a difference may reflect changed workload conditions rather than the code change. A profile is evidence about the captured workload, not a universal ranking of costs across production.
Representative profiles can also inform Go’s profile-guided optimization (PGO). Go’s PGO documentation warns that an unrepresentative profile may yield little or no production improvement. It reports that, as of Go 1.22, representative Go benchmarks showed performance improvements in the range of around 2–14%; that result is a benchmark range, not a promised gain for an individual application. See Go PGO documentation.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

