-
Notifications
You must be signed in to change notification settings - Fork 0
/
d2editor_test.go
171 lines (152 loc) · 2.91 KB
/
d2editor_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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package d2editor_test
import (
"encoding/json"
"github.com/vitalick/go-d2editor"
"sync"
"testing"
)
func createEmpty(b *testing.B, wg *sync.WaitGroup) *d2editor.Character {
c, _ := d2editor.NewEmptyCharacter(97)
if wg != nil {
wg.Done()
}
return c
}
func openOne(b *testing.B, wg *sync.WaitGroup) *d2editor.Character {
c, _ := d2editor.Open("LoD-Druid.d2s")
if wg != nil {
wg.Done()
}
return c
}
func openJSON(b *testing.B, wg *sync.WaitGroup) *d2editor.Character {
c, _ := d2editor.OpenJSON("LoD-Druid2.json")
if wg != nil {
wg.Done()
}
return c
}
func saveOne(b *testing.B, c *d2editor.Character, wg *sync.WaitGroup) {
c.GetBytes()
if wg != nil {
wg.Done()
}
}
func saveJSON(b *testing.B, c *d2editor.Character, wg *sync.WaitGroup) {
json.Marshal(c)
if wg != nil {
wg.Done()
}
}
func createSaveEmpty(b *testing.B, wg *sync.WaitGroup) {
saveOne(b, createEmpty(b, nil), nil)
if wg != nil {
wg.Done()
}
}
func openSaveOne(b *testing.B, wg *sync.WaitGroup) {
saveOne(b, openOne(b, nil), nil)
if wg != nil {
wg.Done()
}
}
func openSaveJSON(b *testing.B, wg *sync.WaitGroup) {
saveJSON(b, openJSON(b, nil), nil)
if wg != nil {
wg.Done()
}
}
func BenchmarkCreateEmpty(b *testing.B) {
wg := &sync.WaitGroup{}
b.ResetTimer()
for range make([]struct{}, b.N) {
wg.Add(1)
go createEmpty(b, wg)
}
wg.Wait()
}
func BenchmarkSaveEmpty(b *testing.B) {
wg := &sync.WaitGroup{}
c := createEmpty(b, nil)
b.ResetTimer()
for range make([]struct{}, b.N) {
wg.Add(1)
go saveOne(b, c, wg)
}
wg.Wait()
}
func BenchmarkCreateSaveEmpty(b *testing.B) {
wg := &sync.WaitGroup{}
b.ResetTimer()
for range make([]struct{}, b.N) {
wg.Add(1)
go createSaveEmpty(b, wg)
}
wg.Wait()
}
func BenchmarkOpen(b *testing.B) {
wg := &sync.WaitGroup{}
b.ResetTimer()
for range make([]struct{}, b.N) {
wg.Add(1)
go openOne(b, wg)
}
wg.Wait()
}
func BenchmarkSaveFile(b *testing.B) {
wg := &sync.WaitGroup{}
c := openOne(b, nil)
b.ResetTimer()
for range make([]struct{}, b.N) {
wg.Add(1)
go saveOne(b, c, wg)
}
wg.Wait()
}
func BenchmarkOpenSave(b *testing.B) {
wg := &sync.WaitGroup{}
b.ResetTimer()
for range make([]struct{}, b.N) {
wg.Add(1)
go openSaveOne(b, wg)
}
wg.Wait()
}
func BenchmarkOpenJSON(b *testing.B) {
wg := &sync.WaitGroup{}
b.ResetTimer()
for range make([]struct{}, b.N) {
wg.Add(1)
go openJSON(b, wg)
}
wg.Wait()
}
func BenchmarkSaveJSON(b *testing.B) {
wg := &sync.WaitGroup{}
c := openJSON(b, nil)
b.ResetTimer()
for range make([]struct{}, b.N) {
wg.Add(1)
go saveJSON(b, c, wg)
}
wg.Wait()
}
func BenchmarkOpenSaveJSON(b *testing.B) {
wg := &sync.WaitGroup{}
b.ResetTimer()
for range make([]struct{}, b.N) {
wg.Add(1)
go openSaveJSON(b, wg)
}
wg.Wait()
}
func BenchmarkOpenD2sSaveJSON(b *testing.B) {
c := openOne(b, nil)
wg := &sync.WaitGroup{}
b.ResetTimer()
for range make([]struct{}, b.N) {
wg.Add(1)
go saveJSON(b, c, wg)
}
wg.Wait()
}