/
benchmark_test.go
62 lines (44 loc) · 1.61 KB
/
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
package mimeheader_test
import (
"testing"
"github.com/aohorodnyk/mimeheader"
)
func BenchmarkParseAcceptHeaderLong(b *testing.B) {
benchmarkParseAcceptHeader(b, "*/*; q=0.9; s=1, image/*; q=0.9; s=4, application/json; q=0.9; b=3;, text/plain")
}
func BenchmarkParseAcceptHeaderThreeWithWights(b *testing.B) {
benchmarkParseAcceptHeader(b, "*/*; q=0.9;, image/*; q=0.9, application/json; q=0.9")
}
func BenchmarkParseAcceptHeaderOne(b *testing.B) {
benchmarkParseAcceptHeader(b, "*/*")
}
func BenchmarkParseAcceptHeaderAndCompareLong(b *testing.B) {
header := "*/*; q=0.9; s=1, image/*; q=0.9; s=4, application/json; q=0.9; b=3;, text/plain"
negotiate := []string{"application/json", "application/xml"}
benchmarkParseAcceptHeaderAndCompare(b, header, negotiate)
}
func BenchmarkParseAcceptHeaderAndCompareThreeWithWights(b *testing.B) {
header := "*/*; q=0.9;, image/*; q=0.9, application/json; q=0.9"
negotiate := []string{"application/json", "application/xml"}
benchmarkParseAcceptHeaderAndCompare(b, header, negotiate)
}
func BenchmarkParseAcceptHeaderAndCompareOne(b *testing.B) {
header := "*/*"
negotiate := []string{"application/json", "application/xml"}
benchmarkParseAcceptHeaderAndCompare(b, header, negotiate)
}
func benchmarkParseAcceptHeaderAndCompare(b *testing.B, header string, negotiate []string) {
b.Helper()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
ah := mimeheader.ParseAcceptHeader(header)
ah.Negotiate(negotiate, "")
}
}
func benchmarkParseAcceptHeader(b *testing.B, header string) {
b.Helper()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
mimeheader.ParseAcceptHeader(header)
}
}