Skip to content

Commit f9c026b

Browse files
committed
Update README.md
Born here and right now
1 parent 55d0342 commit f9c026b

File tree

1 file changed

+100
-1
lines changed

1 file changed

+100
-1
lines changed

README.md

+100-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,101 @@
11
# benchgraph
2-
Visualization of Golang benchmark output using Google graph
2+
Visualization of Golang benchmark output using Google charts
3+
4+
## Introduction
5+
In Golang we can analyze algorithm efficiency by writing benchmark functions and looking at execution time in ns/op. This task might become significantly hindered by increasing number of benchmark tests. One way to handle this is to visualize multiple benchmark results and track the function curve on a graph. The `benchgraph` reads benchmark output lines, prepare data for the graph, and upload data to remote server, which enables online view and html embedding. Graph turns out to be very handy in case of many algorithms that are tested against many arguments, especially if you are studing internal algorithm design.
6+
7+
## Installation
8+
9+
```bash
10+
git clone https://github.com/CodingBerg/benchgraph.git
11+
cd ./benchmark
12+
go get ./
13+
go install
14+
```
15+
16+
## Naming convention
17+
In order for `benchgraph` to work a coder is required to follow the **naming convention** when coding benchmark functions:
18+
```go
19+
// Naming convention
20+
func Benchmark[Function_name]_[Function_argument](b *testing.B){
21+
...
22+
}
23+
```
24+
For example, if we take one line from the benchmark output,
25+
```bash
26+
BenchmarkF1_F-4 30000000 53.7 ns/op
27+
```
28+
it will be parsed and plotted on graph as function `F1(F)=53.7`, taking `F` as an argument and `53.7` as function result.
29+
In short, X-axis shows function arguments, while Y-axis shows function execution time in ns/op.
30+
31+
## Usage
32+
The output of benchmark is piped through `benchgraph`:
33+
34+
```bash
35+
go test -bench .|benchgraph -title="Graph: F(x) in ns/op"
36+
testing: warning: no tests to run
37+
? PASS
38+
√ BenchmarkF1_F-4 30000000 53.7 ns/op
39+
√ BenchmarkF1_FF-4 20000000 62.9 ns/op
40+
√ BenchmarkF1_FFF-4 20000000 70.0 ns/op
41+
√ BenchmarkF1_FFFF-4 20000000 80.3 ns/op
42+
√ BenchmarkF1_FFFFF-4 20000000 90.8 ns/op
43+
√ BenchmarkF1_FFFFFF-4 20000000 99.5 ns/op
44+
...
45+
Waiting for server response ...
46+
=========================================
47+
48+
http://benchgraph.codingberg.com/1
49+
50+
=========================================
51+
```
52+
53+
In front of every line `benchgraph` places indicator whether line is parsed correctly, or not.
54+
When you see red marks `-` or `?`, it means, either you do not follow the **naming convention** from above, or the line doesn't contain benchmark test at all. At the end, `benchgraph` returns URL to the graph. From there, follow instructions how to embed graph into custom HTML page. Also, you can just share the graph link.
55+
56+
## Help
57+
58+
```bash
59+
benchgraph -help
60+
Usage of benchgraph:
61+
-apiurl string
62+
url to server api (default "http://benchgraph.codingberg.com")
63+
-oba value
64+
comma-separated list of benchmark arguments (default [])
65+
-obn value
66+
comma-separated list of benchmark names (default [])
67+
-title string
68+
title of a graph (default "Graph: Benchmark results in ns/op")
69+
```
70+
71+
You can filter out which functions and against which arguments you want to display on graph by passing `-obn` and `-oba` arguments. This can be very handy in case when performing many benchmark tests.
72+
73+
```bash
74+
go test -bench .|benchgraph -title="Graph1: Benchmark F(x) in ns/op" -obn="F2,F3,F4" -oba="F,FF,FFF,FFFF,FFFFF,FFFFFF,FFFFFFF,FFFFFFFF"
75+
```
76+
77+
## Hints on productivity
78+
79+
You can first save benchmark output and then use it later for drawing graphs. This is very handy if your benchmark tests take some time to complete.
80+
81+
```bash
82+
go test -bench . > out
83+
84+
cat out|benchgraph -title="Graph1: Benchmark F(x) in ns/op" -obn="F2,F3,F4" -oba="F,FF,FFF,FFFF,FFFFF,FFFFFF,FFFFFFF,FFFFFFFF"
85+
cat out|benchgraph -title="Graph2: Benchmark F(x) in ns/op" -obn="F2,F3,F4" -oba="0F,F0,F00,F000,F0000,F00000,F000000,F0000000"
86+
```
87+
88+
## Online Demo
89+
90+
Here we analyze efficiency of different algorithms for computing parity of uint64 numbers:
91+
92+
http://codingberg.com/golang/interview/compute_parity_of_64_bit_unsigned_integer
93+
94+
There are two graphs embedded into page behind above link:
95+
96+
http://benchgraph.codingberg.com/1
97+
98+
http://benchgraph.codingberg.com/2
99+
100+
*Both above links can be also shared without emebeding into HTML page.*
101+

0 commit comments

Comments
 (0)