-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmarshal_benchmark_test.go
77 lines (65 loc) · 1.4 KB
/
marshal_benchmark_test.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
package netscape_test
import (
"os"
"testing"
"github.com/virtualtam/netscape-go/v2"
)
var (
cases = []struct {
name string
filepath string
}{
{
name: "flat: 100 bookmarks",
filepath: "testdata/flat100.htm",
},
{
name: "flat: 1000 bookmarks",
filepath: "testdata/flat1000.htm",
},
{
name: "flat: 10000 bookmarks",
filepath: "testdata/flat10000.htm",
},
}
)
func BenchmarkMarshal(b *testing.B) {
b.ReportAllocs()
for _, tc := range cases {
b.Run(tc.name, func(b *testing.B) {
bytes, err := os.ReadFile(tc.filepath)
if err != nil {
b.Fatalf("failed to open file %q: %s", tc.filepath, err)
}
document, err := netscape.Unmarshal(bytes)
if err != nil {
b.Fatalf("failed to open file %q: %s", tc.filepath, err)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := netscape.Marshal(document)
if err != nil {
b.Fatalf("failed to marshal document: %s", err)
}
}
})
}
}
func BenchmarkUnmarshal(b *testing.B) {
b.ReportAllocs()
for _, tc := range cases {
b.Run(tc.name, func(b *testing.B) {
bytes, err := os.ReadFile(tc.filepath)
if err != nil {
b.Fatalf("failed to open file %q: %s", tc.filepath, err)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := netscape.Unmarshal(bytes)
if err != nil {
b.Fatalf("failed to open file %q: %s", tc.filepath, err)
}
}
})
}
}