...
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 package main
30
31 import (
32 "flag"
33 "fmt"
34 "io/ioutil"
35 "os/exec"
36 "sort"
37 "strings"
38 )
39
40 func bench(folder, rgx, outFileName string) {
41 var test = exec.Command("go", "test", "-test.timeout=20m", "-test.v", "-test.run=XXX", "-test.bench="+rgx, folder)
42 fmt.Printf("benching %v - %v - %v\n", folder, rgx, outFileName)
43 out, err := test.CombinedOutput()
44 fmt.Printf("bench output: %v\n", string(out))
45 if err != nil {
46 panic(err)
47 }
48 if err := ioutil.WriteFile(outFileName, out, 0666); err != nil {
49 panic(err)
50 }
51 }
52
53 func main() {
54 flag.Parse()
55 fmt.Printf("Running benches: %v\n", benchList)
56 for _, bench := range strings.Split(benchList, " ") {
57 b, ok := benches[bench]
58 if !ok {
59 fmt.Printf("No benchmark with name: %v\n", bench)
60 continue
61 }
62 b()
63 }
64 if strings.Contains(benchList, "all") {
65 fmt.Println("Running benchcmp will show the performance difference between using reflect and generated code for marshalling and unmarshalling of protocol buffers")
66 fmt.Println("benchcmp ./test/mixbench/marshal.txt ./test/mixbench/marshaler.txt")
67 fmt.Println("benchcmp ./test/mixbench/unmarshal.txt ./test/mixbench/unmarshaler.txt")
68 }
69 }
70
71 var benches = make(map[string]func())
72
73 var benchList string
74
75 func init() {
76 benches["marshaler"] = func() { bench("./test/combos/both/", "ProtoMarshal", "./test/mixbench/marshaler.txt") }
77 benches["marshal"] = func() { bench("./test/", "ProtoMarshal", "./test/mixbench/marshal.txt") }
78 benches["unmarshaler"] = func() { bench("./test/combos/both/", "ProtoUnmarshal", "./test/mixbench/unmarshaler.txt") }
79 benches["unmarshal"] = func() { bench("./test/", "ProtoUnmarshal", "./test/mixbench/unmarshal.txt") }
80 var ops []string
81 for k := range benches {
82 ops = append(ops, k)
83 }
84 sort.Strings(ops)
85 benches["all"] = benchall(ops)
86 ops = append(ops, "all")
87 flag.StringVar(&benchList, "benchlist", "all", fmt.Sprintf("List of benchmarks to run. Options: %v", ops))
88 }
89
90 func benchall(ops []string) func() {
91 return func() {
92 for _, o := range ops {
93 benches[o]()
94 }
95 }
96 }
97
View as plain text