• This repository has been archived on 05/Aug/2022
  • Stars
    star
    341
  • Rank 123,998 (Top 3 %)
  • Language
    Go
  • License
    Apache License 2.0
  • Created about 5 years ago
  • Updated about 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A CLI to turn Go's benchmark output into pictures

benchdraw

CircleCI GoDoc codecov

benchdraw allows you to make easy to read picture plots from data in Go's benchmark format, implemented in pure Go.

Benchdraw does not try to be as configurable or good looking as gnuplot. It only intends to produce good enough pictures for the most common cases that users can generate with minimal effort.

Install

go get github.com/cep21/benchdraw

Usage

First generate some benchmark data by running your benchmarks and sending them to a file. Here is what my makefile looks like:

bench:
    go test -v -benchmem -run=^$$ -bench=. ./... > benchmark.txt

Then, run benchdraw against benchmark.txt to create pictures. benchdraw expects that you name your benchmarks as described by https://github.com/golang/proposal/blob/master/design/14313-benchmark-format.md

Importantly, that you use key=value format to group your sub benchmarks and that / divides the key space. For example

BenchmarkDecode/text=digits/level=speed/size=1e4-8   	     100	    154125 ns/op	  64.88 MB/s	   40418 B/op	       7 allocs/op
BenchmarkDecode/text=digits/level=speed/size=1e5-8   	      10	   1367632 ns/op	  73.12 MB/s	   41356 B/op	      14 allocs/op
BenchmarkDecode/text=digits/level=speed/size=1e6-8   	       1	  13879794 ns/op	  72.05 MB/s	   52056 B/op	      94 allocs/op
BenchmarkDecode/text=digits/level=default/size=1e4-8 	     100	    147551 ns/op	  67.77 MB/s	   40418 B/op	       8 allocs/op
BenchmarkDecode/text=digits/level=default/size=1e5-8 	      10	   1197672 ns/op	  83.50 MB/s	   41508 B/op	      13 allocs/op

There are example pictures inside examples and example benchmark results inside testdata. Run make draw_examples to see all the examples drawn.

Simple example

Here we filter the benchmarks to just the ones named "BenchmarkTdigest_Add" and plot the tag "source" as our X dimension. The default Y dimension is ns/op.

# Sample line from simpleres.txt
# BenchmarkTdigest_Add/source=linear/digest=caio-8 	 1299153	       932 ns/op	      33 B/op	       0 allocs/op
#
./benchdraw --filter="BenchmarkTdigest_Add" --x=source < ./testdata/simpleres.txt > ./examples/out0.svg

firts example

Reading from a file

You can run the same simple example another way, passing directly the input and output file names

./benchdraw --filter="BenchmarkTdigest_Add" --x=source --group="digest" --input=./testdata/simpleres.txt --output=./examples/out1.svg

firts example

Plot another metric

You can set the "y" value to plot. Here I set it to allocs/op. Notice how the table at the top right "digits/twain" bleeds into the bar graph. For this case, it may be better to use a line output (see below).

# Sample line from decodeexample.txt
# BenchmarkDecode/text=digits/level=best/size=1e5-8    	      10	   1185527 ns/op	  84.35 MB/s	   41508 B/op	      13 allocs/op
#
./benchdraw --filter="BenchmarkDecode/level=best" --x=size --y="allocs/op" --input=./testdata/decodeexample.txt --output=./examples/sample_allocs.svg

line output

Line output

Bar graphs are the default, but you can also output line charts. This can help if the table at the top gets in the way.

./benchdraw --filter="BenchmarkDecode/level=best" --x=size --plot=line --y="allocs/op" --input=./testdata/decodeexample.txt --output=./examples/sample_line.svg

line output

Here is another example line output

# Sample line from benchresult.txt
# BenchmarkCorrectness/size=1000000/source=rand/digest=caio/quant=0.000000-8                  	1000000000	         0.0649 ns/op	       100 %correct	       0 B/op	       0 allocs/op
    ./benchdraw --filter="BenchmarkCorrectness/size=1000000/quant=0.000000" --x=source --plot=line --y=%correct --v=4 --input=./testdata/benchresult.txt --output=./examples/sample_line3.svg

line output

Custom metrics

You can also plot benchmark results of custom metrics. Here I plot the custom metric %correct.

	./benchdraw --filter="BenchmarkCorrectness/size=1000000/digest=segmentio" --x=quant --y=%correct --v=4 --input=./testdata/benchresult.txt --output=./examples/segmentio_correct.svg

line output

Grouping

Sometimes your benchmarks have too many dimensions to read easily

	./benchdraw --filter="BenchmarkCorrectness/size=1000000" --x=quant --y=%correct --v=4 --input=./testdata/benchresult.txt --output=./examples/too_many.svg

line output

You can group those bars. By default, grouping aggregates with a mean(average) function. Here I try to show, on average, how correct two different implementations of the tdigest algorithm are as quantiles increase.

./benchdraw --filter="BenchmarkCorrectness/size=1000000" --x=quant --y=%correct --group="digest" --v=4 --input=./testdata/benchresult.txt --output=./examples/grouped.svg

line output

Using benchmark key/value tags

You can use the benchmark format's support for tagged data to chart changes over time. Here is an example file.

commit: 7cd9055
BenchmarkDecode/text=digits/level=speed/size=1e4-8   	     100	    154125 ns/op	  64.88 MB/s	   40418 B/op	       7 allocs/op
commit: 3ab3ace
BenchmarkDecode/text=digits/level=speed/size=1e4-8   	     100	    154125 ns/op	  64.88 MB/s	   40418 B/op	       7 allocs/op
commit: 92ae1af
BenchmarkDecode/text=digits/level=speed/size=1e4-8   	     100	    167185 ns/op	  64.88 MB/s	   40418 B/op	       7 allocs/op
commit: 920af9b
BenchmarkDecode/text=digits/level=speed/size=1e4-8   	     100	    168129 ns/op	  64.88 MB/s	   40418 B/op	       7 allocs/op
commit: a1b93a0
BenchmarkDecode/text=digits/level=speed/size=1e4-8   	     100	    140125 ns/op	  64.88 MB/s	   40418 B/op	       7 allocs/op

Notice how each benchmark run contains the tag "commit". We can use commit as our x axis

./benchdraw --filter="BenchmarkDecode" --x=commit --plot=line --input=./testdata/encodeovertime.txt --output=./examples/comits.svg

line output

Parameter explanations

x (required)

A x parameter should be a tag or dimension of your benchmark and will get distributed on the X axis of your image.

y

A y parameter should be a unit of one of your benchmark runs The default is "ns/op".

filter

A filter limits which benchmarks we consider. It is in a similar format to the expected benchmark output. Each / segment is a filter. If the filter has =, then it is an exact match. If the filter has just a word, then it's an existence match for that word. For example BenchmarkDecode/text=digits matches

  • BenchmarkDecode/name=bob/text=digits
  • BenchmarkDecode/text=digits.

Does not match

  • BenchmarkDecode
  • BenchmarkDecode/text=sawyer

Design Rational

The tool will never be as powerful as gnuplot. My hope was to capture the most common cases.

Contributing

Contributions welcome! Submit a pull request on github and make sure your code passes make lint test. For large changes, I strongly recommend creating an issue on GitHub first to confirm your change will be accepted before writing a lot of code. GitHub issues are also recommended, at your discretion, for smaller changes or questions.

License

This library is licensed under the Apache 2.0 License.

More Repositories

1

circuit

An efficient and feature complete Hystrix like Go implementation of the circuit breaker pattern.
Go
763
star
2

healthcheck_nginx_upstreams

Health checks upstreams for nginx
C
252
star
3

jackbash

My bash startup script
Shell
72
star
4

gotemplate

Minimal repository template for well constructed Go libraries.
Makefile
34
star
5

tdigestbench

Benchmark various tdigest implementations
Go
11
star
6

go-talks

My various slides for Go
9
star
7

benchparse

An API to parse Go's benchmark format
Go
8
star
8

xdgbasedir

XDG Base Directory Specification for golang
Go
7
star
9

smitego

A Go interface to Smite's API
Go
6
star
10

goverify

A windows/mac/linux way to verify golang code is ok
Go
5
star
11

syntasticarc

Arc support for vim and syntastic
Python
4
star
12

cwopencensusexporter

CloudWatch open census exporter
Go
3
star
13

golanguk2017

Go
3
star
14

reddit_counts

PHP code for a better reddit RSS feed: http://cep21.net/rssfeeds/reddit_counts.php
PHP
2
star
15

aimdcloser

Additive increase/multiplicative decrease circuit closer
Go
2
star
16

gobuild

Build tool for go code
Go
2
star
17

serviceexecutor

Manage long running service goroutines
Go
2
star
18

distconf

A distributed configuration framework
Go
1
star
19

geneticsort

Genetic algorithm for worst case go.Sort
Go
1
star
20

fbgifs

Show gifs on facebook!
JavaScript
1
star
21

cad_comic

RSS feed of cad comics with image inline
PHP
1
star
22

penny_comics

Penny comics RSS feed w/ images inside
PHP
1
star
23

cfexecute

More user friendly cloudformation execution
Go
1
star
24

ecsrun

Simple way to run ecs tasks inside a cluster, stream output, and exit with the right code
Go
1
star
25

awsexpvar

Exposes AWS instance information via expvar
Go
1
star
26

resume_template

A template latex resume on Github
TeX
1
star
27

blog-comments

Just for providing giscus comments for my blog https://cep.dev
1
star