forked from codingberg/benchgraph
-
Notifications
You must be signed in to change notification settings - Fork 3
/
format.go
35 lines (30 loc) · 759 Bytes
/
format.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
package main
import (
"bytes"
"fmt"
)
// graphData translate bench results to Google graph JSON structure
func graphData(benchResults BenchNameSet, oBenchNames, oBenchArgs stringList) []byte {
data := new(bytes.Buffer)
data.WriteString("[")
sep := ""
data.WriteString("[\"Argument\"")
for _, oName := range oBenchNames {
sep = ","
data.WriteString(fmt.Sprintf("%s\"%s\"", sep, oName))
}
data.WriteString("]")
lsep := ""
for _, oArg := range oBenchArgs {
lsep = ","
data.WriteString(fmt.Sprintf("%s[\"%s\"", lsep, oArg))
sep := ""
for _, oName := range oBenchNames {
sep = ","
data.WriteString(fmt.Sprintf("%s%.2f", sep, benchResults[oName][oArg]))
}
data.WriteString("]")
}
data.WriteString("]")
return data.Bytes()
}