memcpu

command
v0.0.0-...-b2ac4ad Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

README


title: "Benchmark Profiling" weight: 2

Benchmark Profiling

Using benchmarks you can profile your programs and see exactly where your performance or memory is being taken.

Profiling Commands

CPU Profiling

Run the benchmark.

$ go test -run none -bench . -benchtime 3s -benchmem -cpuprofile p.out

Run the pprof tool using the command line tooling.

$ go tool pprof p.out

Run these pprof commands.

(pprof) list algOne
(pprof) web list algOne

Run the pprof tool using the browser based tooling.

$ go tool pprof -http :3000 p.out

Navigate the drop down menu in the UI.

Run the pprof tool using including the memcpu.test binary.

$ go tool pprof -http :3000 memcpu.test p.out

When you do this, you can get profiling information down to the assembly level.

Memory Profiling

Run the benchmark.

$ go test -run none -bench . -benchtime 3s -benchmem -memprofile p.out

Run the pprof tool.

$ go tool pprof -<OPTIONAL_PICK_MEM_PROFILE> p.out

Run these pprof commands.

(pprof) list algOne
(pprof) web list algOne

Run the pprof tool using the browser based tooling.

$ go tool pprof -<OPTIONAL_PICK_MEM_PROFILE> -http :3000 p.out

Navigate the drop down menu in the UI.

Run the pprof tool using including the memcpu.test binary.

$ go tool pprof -<OPTIONAL_PICK_MEM_PROFILE> -http :3000 memcpu.test p.out

When you do this, you can get profiling information down to the assembly level.

Documentation of memory profile options.

// Useful to see pressure on heap over time.
-alloc_space  : All allocations happened since program start ** default
-alloc_objects: Number of object allocated at the time of profile

// Useful to see current status of heap.
-inuse_space  : Allocations live at the time of profile
-inuse_objects: Number of bytes allocated at the time of profile

If you want to reduce memory consumption, look at the -inuse_space profile collected during normal program operation.

If you want to improve execution speed, look at the -alloc_objects profile collected after significant running time or at program end.

Code Review

Profiling (Go Playground) | Profiling Test (Go Playground)


All material is licensed under the Apache License Version 2.0, January 2004.

Documentation

Overview

Sample program that takes a stream of bytes and looks for the bytes “elvis” and when they are found, replace them with “Elvis”. The code cannot assume that there are any line feeds or other delimiters in the stream and the code must assume that the stream is of any arbitrary length. The solution cannot meaningfully buffer to the end of the stream and then process the replacement.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL