-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbench_test.go
55 lines (46 loc) · 1.08 KB
/
bench_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
// SPDX-FileCopyrightText: 2019-2024 caixw
//
// SPDX-License-Identifier: MIT
package qheader
import (
"testing"
"github.com/issue9/assert/v4"
)
func BenchmarkParseItem(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = parseItem("application/xml;q=0.9")
}
}
func BenchmarkParse(b *testing.B) {
a := assert.New(b, false)
b.Run("4", func(b *testing.B) {
str := "application/json;q=0.9,text/plain;q=0.8,text/html,text/xml,*/*;q=0.1"
for i := 0; i < b.N; i++ {
qh := Parse(str, "*/*")
a.True(len(qh.Items) > 0)
}
})
b.Run("pool-4", func(b *testing.B) {
str := "application/json;q=0.9,text/plain;q=0.8,text/html,text/xml,*/*;q=0.1"
for i := 0; i < b.N; i++ {
qh := Parse(str, "*/*")
a.True(len(qh.Items) > 0)
qh.Destroy()
}
})
b.Run("1", func(b *testing.B) {
str := "application/json;q=0.9"
for i := 0; i < b.N; i++ {
qh := Parse(str, "*/*")
a.True(len(qh.Items) > 0)
}
})
b.Run("pool-1", func(b *testing.B) {
str := "application/json;q=0.9"
for i := 0; i < b.N; i++ {
qh := Parse(str, "*/*")
a.True(len(qh.Items) > 0)
qh.Destroy()
}
})
}