benchplot

package
v0.0.0-...-9a956c0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2021 License: MIT Imports: 11 Imported by: 0

README

benchplot

Plotinum helpers for benchkit.

PlotMemory

The example:

files := GenTarFiles(n, size)

results := benchkit.Bench(benchkit.Memory(n)).Each(func(each benchkit.BenchEach) {
    for j, file := range files {
        each.Before(j)
        // file -> tar
        each.After(j)
    }
}).(*benchkit.MemResult)

p, _ := PlotMemory(
    fmt.Sprintf("archive/tar memory usage for %d files, %s each", n, humanize.Bytes(uint64(size))),
    "Files in archive",
    results,
)
_ = p.Save(6, 4, "tar_memplot.svg")

Yields the graph:

Example of a memory usage plot

PlotTime

Similarly:

files := GenTarFiles(n, size)

results := benchkit.Bench(benchkit.Time(n, times)).Each(func(each benchkit.BenchEach) {
    for repeat := 0; repeat < times; repeat++ {
        // reset
        for j, file := range files {
            each.Before(j)
            // file -> tar
            each.After(j)
        }
    }

}).(*benchkit.TimeResult)

p, _ := PlotTime(
    fmt.Sprintf("archive/tar time usage for %d files, %s each, over %d measurements", n, humanize.Bytes(uint64(size)), times),
    "Files in archive",
    results,
)
_ = p.Save(6, 4, "tar_timeplot.svg")

Yields the graph:

Example of a time plot

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func PlotMemory

func PlotMemory(title, xLabel string, results *benchkit.MemResult, logscale bool) (*plot.Plot, error)

PlotMemory will create a line graph of AfterEach measurements. The lines plotted are:

current heap size            : HeapAlloc
total heap size              : HeapSys
memory allocated from OS     : Sys
effective memory consumption : Sys - HeapReleased

The Y axis is implicitely measured in Bytes.

Example
n := 100
size := int(1e6)
buf := bytes.NewBuffer(nil)

memkit, results := benchkit.Memory(n)

memkit.Setup()
files := GenTarFiles(n, size)
memkit.Starting()

each := memkit.Each()

buf.Reset()
tarw := tar.NewWriter(buf)
for j, file := range files {
	each.Before(j)
	_ = tarw.WriteHeader(file.TarHeader())
	_, _ = tarw.Write(file.Data())
	each.After(j)
}
_ = tarw.Close()

memkit.Teardown()

p, _ := PlotMemory(
	fmt.Sprintf("archive/tar memory usage for %d files, %s each", n, humanize.Bytes(uint64(size))),
	"Files in archive",
	results,
	false,
)
_ = p.Save(960, 720, "tar_memplot.svg")
Output:

Example (Bench)
n := 100
size := int(1e6)
buf := bytes.NewBuffer(nil)

files := GenTarFiles(n, size)

results := benchkit.Bench(benchkit.Memory(n)).Each(func(each benchkit.BenchEach) {
	buf.Reset()
	tarw := tar.NewWriter(buf)
	for j, file := range files {
		each.Before(j)
		_ = tarw.WriteHeader(file.TarHeader())
		_, _ = tarw.Write(file.Data())
		each.After(j)
	}
	_ = tarw.Close()

}).(*benchkit.MemResult)

p, _ := PlotMemory(
	fmt.Sprintf("archive/tar memory usage for %d files, %s each", n, humanize.Bytes(uint64(size))),
	"Files in archive",
	results,
	false,
)
_ = p.Save(960, 720, "tar_memplot.png")
Output:

func PlotTime

func PlotTime(title, xLabel string, results *benchkit.TimeResult, logscale bool) (*plot.Plot, error)

PlotTime does stuff.

Example
n := 100
times := 100
size := int(1e6)
buf := bytes.NewBuffer(nil)

timekit, results := benchkit.Time(n, times)

timekit.Setup()
files := GenTarFiles(n, size)
timekit.Starting()

each := timekit.Each()

for i := 0; i < times; i++ {
	buf.Reset()
	tarw := tar.NewWriter(buf)
	for j, file := range files {
		each.Before(j)
		_ = tarw.WriteHeader(file.TarHeader())
		_, _ = tarw.Write(file.Data())
		each.After(j)
	}
	_ = tarw.Close()
}

timekit.Teardown()

p, _ := PlotTime(
	fmt.Sprintf("archive/tar time usage for %d files, %s each, over %d measurements", n, humanize.Bytes(uint64(size)), times),
	"Files in archive",
	results,
	true,
)
_ = p.Save(960, 720, "tar_timeplot.svg")
Output:

Example (Bench)
n := 100
times := 100
size := int(1e6)
buf := bytes.NewBuffer(nil)

files := GenTarFiles(n, size)

results := benchkit.Bench(benchkit.Time(n, times)).Each(func(each benchkit.BenchEach) {
	for repeat := 0; repeat < times; repeat++ {
		buf.Reset()
		tarw := tar.NewWriter(buf)
		for j, file := range files {
			each.Before(j)
			_ = tarw.WriteHeader(file.TarHeader())
			_, _ = tarw.Write(file.Data())
			each.After(j)
		}
		_ = tarw.Close()
	}

}).(*benchkit.TimeResult)

p, _ := PlotTime(
	fmt.Sprintf("archive/tar time usage for %d files, %s each, over %d measurements", n, humanize.Bytes(uint64(size)), times),
	"Files in archive",
	results,
	true,
)
_ = p.Save(960, 720, "tar_timeplot.png")
Output:

Types

This section is empty.

Jump to

Keyboard shortcuts

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