-
Notifications
You must be signed in to change notification settings - Fork 2
/
section_benchmark_test.go
59 lines (52 loc) · 1.25 KB
/
section_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
package specfile
import (
"strings"
"testing"
"unicode"
"unicode/utf8"
)
func (s *Section) parse1(token *Tokenizer) {
s.Raw = token
lines := strings.Split(token.Content, "-n")
if len(lines) > 1 {
// "%post -n fcitx5-configtool -p /sbin/ldconfig"
s.Name = strings.TrimSpace(lines[0])
var belongs []byte
for _, v := range []byte(strings.TrimSpace(lines[1])) {
r, _ := utf8.DecodeRune([]byte{v})
if unicode.IsSpace(r) {
break
}
belongs = append(belongs, v)
}
s.Belongs = string(belongs)
s.Value = strings.TrimSpace(strings.Replace(lines[1], string(belongs), "", 1))
} else {
// "%post -p /sbin/ldconfig"
var name []byte
for _, v := range []byte(token.Content) {
r, _ := utf8.DecodeRune([]byte{v})
if unicode.IsSpace(r) {
break
}
name = append(name, v)
}
s.Name = string(name)
s.Value = strings.TrimSpace(strings.Replace(token.Content, s.Name, "", 1))
}
}
var sectiontoken = NewTokenizer("Section", "%post -n fcitx5-configtool -p /sbin/ldconfig")
func BenchmarkSectionParse(b *testing.B) {
b.ResetTimer()
var s Section
for i := 0; i < b.N; i++ {
s.Parse(§iontoken)
}
}
func BenchmarkSectionParse1(b *testing.B) {
b.ResetTimer()
var s Section
for i := 0; i < b.N; i++ {
s.parse1(§iontoken)
}
}