benchmark

package standard library
go1.17.10 Latest Latest
Warning

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

Go to latest
Published: May 10, 2022 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Overview

Package benchmark provides a Metrics object that enables memory and CPU profiling for the linker. The Metrics objects can be used to mark stages of the code, and name the measurements during that stage. There is also optional GCs that can be performed at the end of each stage, so you can get an accurate measurement of how each stage changes live memory.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Flags

type Flags int
const (
	GC         = 1 << iota
	NoGC Flags = 0
)

type Metrics

type Metrics struct {
	// contains filtered or unexported fields
}

func New

func New(gc Flags, filebase string) *Metrics

New creates a new Metrics object.

Typical usage should look like:

func main() {
  filename := "" // Set to enable per-phase pprof file output.
  bench := benchmark.New(benchmark.GC, filename)
  defer bench.Report(os.Stdout)
  // etc
  bench.Start("foo")
  foo()
  bench.Start("bar")
  bar()
}

Note that a nil Metrics object won't cause any errors, so one could write code like:

func main() {
  enableBenchmarking := flag.Bool("enable", true, "enables benchmarking")
  flag.Parse()
  var bench *benchmark.Metrics
  if *enableBenchmarking {
    bench = benchmark.New(benchmark.GC)
  }
  bench.Start("foo")
  // etc.
}

func (*Metrics) Report

func (m *Metrics) Report(w io.Writer)

Report reports the metrics. Closes the currently Start(ed) range, and writes the report to the given io.Writer.

func (*Metrics) Start

func (m *Metrics) Start(name string)

Starts marks the beginning of a new measurement phase. Once a metric is started, it continues until either a Report is issued, or another Start is called.

Jump to

Keyboard shortcuts

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