-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathitem_benchmark_test.go
58 lines (48 loc) · 1000 Bytes
/
item_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
package specfile
import (
"strings"
"testing"
)
func (i *item) parse1(token *Tokenizer) {
i.Raw = token
// Name: xz
var j int
name := make([]byte, strings.Index(token.Content, ":"))
for _, v := range []byte(token.Content) {
if v == ':' {
break
}
name[j] = v
j++
}
i.Name = string(name)
i.Value = strings.TrimSpace(strings.Replace(token.Content, string(name)+":", "", 1))
}
func (i *item) parse2(token *Tokenizer) {
i.Raw = token
arr := strings.Split(token.Content, ":")
i.Name = arr[0]
i.Value = strings.TrimSpace(arr[1])
}
var itemtoken = NewTokenizer("Tag", "Name: fcitx5\n")
func BenchmarkItemParse(b *testing.B) {
b.ResetTimer()
var it item
for i := 0; i < b.N; i++ {
it.Parse(&itemtoken)
}
}
func BenchmarkItemParse1(b *testing.B) {
b.ResetTimer()
var it item
for i := 0; i < b.N; i++ {
it.parse1(&itemtoken)
}
}
func BenchmarkItemParse2(b *testing.B) {
b.ResetTimer()
var it item
for i := 0; i < b.N; i++ {
it.parse2(&itemtoken)
}
}