perfgolang.org/x/perf/storage/benchfmt Index | Files

package benchfmt

import "golang.org/x/perf/storage/benchfmt"

Package benchfmt provides readers and writers for the Go benchmark format.

The format is documented at https://golang.org/design/14313-benchmark-format

This package only parses file configuration lines, not benchmark result lines. Parsing the result lines is left to the caller.

Deprecated: See the golang.org/x/perf/benchfmt package, which implements readers and writers for the full Go benchmark format. It is also higher performance.

Index

Types

type Labels

type Labels map[string]string

Labels is a set of key-value strings.

func (Labels) Copy

func (l Labels) Copy() Labels

Copy returns a new copy of the labels map, to protect against future modifications to labels.

func (Labels) Equal

func (l Labels) Equal(b Labels) bool

Equal reports whether l and b have the same keys and values.

func (Labels) Keys

func (l Labels) Keys() []string

Keys returns a sorted list of the keys in l.

func (Labels) String

func (l Labels) String() string

String returns the labels formatted as a comma-separated list enclosed in braces.

type Printer

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

A Printer prints a sequence of benchmark results.

func NewPrinter

func NewPrinter(w io.Writer) *Printer

NewPrinter constructs a BenchmarkPrinter writing to w.

func (*Printer) Print

func (p *Printer) Print(r *Result) error

Print writes the lines necessary to recreate r.

type Reader

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

Reader reads benchmark results from an io.Reader. Use Next to advance through the results.

br := benchfmt.NewReader(r)
for br.Next() {
  res := br.Result()
  ...
}
err = br.Err() // get any error encountered during iteration
...

func NewReader

func NewReader(r io.Reader) *Reader

NewReader creates a BenchmarkReader that reads from r.

func (*Reader) AddLabels

func (r *Reader) AddLabels(labels Labels)

AddLabels adds additional labels as if they had been read from the header of a file. It must be called before the first call to r.Next.

func (*Reader) Err

func (r *Reader) Err() error

Err returns the error state of the reader.

func (*Reader) Next

func (r *Reader) Next() bool

Next returns the next benchmark result from the file. If there are no further results, it returns nil, io.EOF.

func (*Reader) Result

func (r *Reader) Result() *Result

Result returns the most recent result generated by a call to Next.

type Result

type Result struct {
	// Labels is the set of persistent labels that apply to the result.
	// Labels must not be modified.
	Labels Labels
	// NameLabels is the set of ephemeral labels that were parsed
	// from the benchmark name/line.
	// NameLabels must not be modified.
	NameLabels Labels
	// LineNum is the line number on which the result was found
	LineNum int
	// Content is the verbatim input line of the benchmark file, beginning with the string "Benchmark".
	Content string
}

Result represents a single line from a benchmark file. All information about that line is self-contained in the Result. A Result is immutable once created.

func (*Result) SameLabels

func (r *Result) SameLabels(b *Result) bool

SameLabels reports whether r and b have the same labels.

Source Files

benchfmt.go

Version
v0.0.0-20250214215153-c95ad7d5b636 (latest)
Published
Feb 14, 2025
Platform
linux/amd64
Imports
8 packages
Last checked
1 week ago

Tools for package owners.