-
Notifications
You must be signed in to change notification settings - Fork 51
/
report.go
104 lines (88 loc) · 2.41 KB
/
report.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package main
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
)
func main() {
libs, tooks0, marshaledBytes := readMarshalLog()
tookFile, _ := os.OpenFile("marshal_took.csv", os.O_CREATE|os.O_RDWR, 0777)
marshaledBytesFile, _ := os.OpenFile("marshaledBytes.csv", os.O_CREATE|os.O_RDWR, 0777)
defer tookFile.Close()
defer marshaledBytesFile.Close()
for i, name := range libs {
tookFile.WriteString(fmt.Sprintf("%s,%d\n", name, tooks0[i]))
marshaledBytesFile.WriteString(fmt.Sprintf("%s,%d\n", name, marshaledBytes[i]))
}
libs, tooks1 := readUnmarshalLog()
tookFile2, _ := os.OpenFile("unmarshal_took.csv", os.O_CREATE|os.O_RDWR, 0777)
defer tookFile2.Close()
for i, name := range libs {
tookFile2.WriteString(fmt.Sprintf("%s,%d\n", name, tooks1[i]))
}
tookFile3, _ := os.OpenFile("lib_took.csv", os.O_CREATE|os.O_RDWR, 0777)
defer tookFile3.Close()
for i, name := range libs {
tookFile3.WriteString(fmt.Sprintf("%s,%d,%d\n", name, tooks0[i], tooks1[i]))
}
}
func readMarshalLog() ([]string, []int, []int) {
file, err := os.Open("marshal.log")
if err != nil {
panic(err)
}
defer file.Close()
var libs []string
var tooks []int
var marshaledBytes []int
scanner := bufio.NewScanner(file)
for scanner.Scan() {
line := scanner.Text()
if strings.HasPrefix(line, "BenchmarkMarshalBy") {
line = strings.TrimPrefix(line, "BenchmarkMarshalBy")
fields := strings.Fields(line)
name := fields[0]
if strings.Index(name, "-") > 0 {
name = name[:strings.Index(name, "-")]
}
libs = append(libs, name)
tooks = append(tooks, int(s2f(fields[2])))
marshaledBytes = append(marshaledBytes, int(s2f(fields[4])))
}
}
return libs, tooks, marshaledBytes
}
func readUnmarshalLog() ([]string, []int) {
file, err := os.Open("unmarshal.log")
if err != nil {
panic(err)
}
defer file.Close()
var libs []string
var tooks []int
scanner := bufio.NewScanner(file)
for scanner.Scan() {
line := scanner.Text()
if strings.HasPrefix(line, "BenchmarkUnmarshalBy") {
line = strings.TrimPrefix(line, "BenchmarkUnmarshalBy")
fields := strings.Fields(line)
name := fields[0]
if strings.Index(name, "-") > 0 {
name = name[:strings.Index(name, "-")]
}
libs = append(libs, name)
tooks = append(tooks, int(s2f(fields[2])))
}
}
return libs, tooks
}
func s2i(s string) int {
f, _ := strconv.Atoi(s)
return f
}
func s2f(s string) float64 {
f, _ := strconv.ParseFloat(s, 64)
return f
}