/
main.go
82 lines (71 loc) · 1.34 KB
/
main.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
"github.com/go-faster/jx"
"golang.org/x/tools/benchmark/parse"
)
func write(b *parse.Benchmark) {
e := jx.GetEncoder()
defer jx.PutEncoder(e)
e.Obj(func(e *jx.Encoder) {
e.FieldStart("name_full")
e.Str(b.Name)
name := strings.TrimPrefix(b.Name, "Benchmark")
var cpus int
{
idx := strings.LastIndex(name, "-")
if idx > 0 {
v, err := strconv.Atoi(name[idx+1:])
if err == nil {
cpus = v
name = name[:idx]
}
}
}
e.FieldStart("name")
e.Str(name)
if cpus > 0 {
e.FieldStart("cpus")
e.Int(cpus)
}
e.FieldStart("count")
e.Int(b.N)
if (b.Measured & parse.NsPerOp) != 0 {
e.FieldStart("duration_ns")
e.Float64(b.NsPerOp)
}
if (b.Measured & parse.MBPerS) != 0 {
e.FieldStart("mb_per_sec")
e.Float64(b.MBPerS)
}
if (b.Measured & parse.AllocedBytesPerOp) != 0 {
e.FieldStart("alloc_bytes")
e.UInt64(b.AllocedBytesPerOp)
}
if (b.Measured & parse.AllocsPerOp) != 0 {
e.FieldStart("alloc_count")
e.UInt64(b.AllocsPerOp)
}
})
fmt.Println(e)
}
func run() error {
s := bufio.NewScanner(os.Stdin)
for s.Scan() {
b, err := parse.ParseLine(s.Text())
if err != nil {
continue
}
write(b)
}
return s.Err()
}
func main() {
if err := run(); err != nil {
fmt.Fprintf(os.Stderr, "%+v\n", err)
}
}