-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgobench2plot.go
67 lines (58 loc) · 1.86 KB
/
gobench2plot.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package main
import (
"bufio"
"fmt"
"os"
"regexp"
)
func main() {
// Examples:
// BenchmarkParsePage 100 17788153 ns/op
// BenchmarkWrite_4KB_WithIndex 50000 61010 ns/op 67.14 MB/s 598 B/op 16 allocs/op
nsExp := regexp.MustCompile("^(Benchmark.+?)\\s+.*?(\\S+) ns/op.*")
allocedBytesExp := regexp.MustCompile("^(Benchmark.+?)\\s+.*?(\\S+) B/op.*")
allocedExp := regexp.MustCompile("^(Benchmark.+?)\\s+.*?(\\S+) allocs/op.*")
mbExp := regexp.MustCompile("^(Benchmark.+?)\\s+.*?(\\S+) MB/s.*")
nsMap := make(map[string]string)
allocedBytesMap := make(map[string]string)
allocedMap := make(map[string]string)
mbMap := make(map[string]string)
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
line := scanner.Text()
if tokens := nsExp.FindStringSubmatch(line); tokens != nil {
nsMap[tokens[1]] = tokens[2]
}
if tokens := allocedBytesExp.FindStringSubmatch(line); tokens != nil {
allocedBytesMap[tokens[1]] = tokens[2]
}
if tokens := allocedExp.FindStringSubmatch(line); tokens != nil {
allocedMap[tokens[1]] = tokens[2]
}
if tokens := mbExp.FindStringSubmatch(line); tokens != nil {
mbMap[tokens[1]] = tokens[2]
}
}
fmt.Printf("<Benchmarks>\n")
fmt.Printf(" <NsPerOp>\n")
for key := range nsMap {
fmt.Printf(" <%v>%v</%v>\n", key, nsMap[key], key)
}
fmt.Printf(" </NsPerOp>\n")
fmt.Printf(" <AllocsBytesPerOp>\n")
for key := range allocedBytesMap {
fmt.Printf(" <%v>%v</%v>\n", key, allocedBytesMap[key], key)
}
fmt.Printf(" </AllocsBytesPerOp>\n")
fmt.Printf(" <AllocsPerOp>\n")
for key := range allocedMap {
fmt.Printf(" <%v>%v</%v>\n", key, allocedMap[key], key)
}
fmt.Printf(" </AllocsPerOp>\n")
fmt.Printf(" <mbPerSec>\n")
for key := range mbMap {
fmt.Printf(" <%v>%v</%v>\n", key, mbMap[key], key)
}
fmt.Printf(" </mbPerSec>\n")
fmt.Printf("</Benchmarks>\n")
}