forked from gofiber/fiber
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_bench_test.go
112 lines (92 loc) · 2.48 KB
/
utils_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
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
// ⚡️ Fiber is an Express inspired web framework written in Go with ☕️
// 📝 Github Repository: https://github.com/gofiber/fiber
// 📌 API Documentation: https://docs.gofiber.io
package fiber
import (
"testing"
)
// go test -v ./... -run=^$ -bench=Benchmark_Utils_toUpper -benchmem -count=3
// func Benchmark_Utils_assertEqual(b *testing.B) {
// // TODO
// }
func Benchmark_Utils_getGroupPath(b *testing.B) {
var res string
for n := 0; n < b.N; n++ {
res = getGroupPath("/v1/long/path/john/doe", "/why/this/name/is/so/awesome")
res = getGroupPath("/v1", "/")
res = getGroupPath("/v1", "/api")
res = getGroupPath("/v1", "/api/register/:project")
}
assertEqual(b, "/v1/api/register/:project", res)
}
func Benchmark_Utils_getMIME(b *testing.B) {
var res string
for n := 0; n < b.N; n++ {
res = getMIME(".json")
res = getMIME(".xml")
res = getMIME("xml")
res = getMIME("json")
}
assertEqual(b, "application/json", res)
}
// func Benchmark_Utils_getArgument(b *testing.B) {
// // TODO
// }
// func Benchmark_Utils_parseTokenList(b *testing.B) {
// // TODO
// }
func Benchmark_Utils_statusMessage(b *testing.B) {
var res string
for n := 0; n < b.N; n++ {
res = statusMessage[100]
res = statusMessage[304]
res = statusMessage[423]
res = statusMessage[507]
}
assertEqual(b, "Insufficient Storage", res)
}
func Benchmark_Utils_extensionMIME(b *testing.B) {
var res string
for n := 0; n < b.N; n++ {
res = getMIME(".json")
res = getMIME("json")
res = getMIME("xspf")
res = getMIME(".xspf")
res = getMIME("avi")
res = getMIME(".avi")
}
assertEqual(b, "video/x-msvideo", res)
}
// func Benchmark_Utils_getParams(b *testing.B) {
// // TODO
// }
// func Benchmark_Utils_matchParams(b *testing.B) {
// // TODO
// }
func Benchmark_Utils_getTrimmedParam(b *testing.B) {
var res string
for n := 0; n < b.N; n++ {
res = getTrimmedParam(":param")
res = getTrimmedParam(":param?")
}
assertEqual(b, "param", res)
}
// func Benchmark_Utils_getCharPos(b *testing.B) {
// // TODO
// }
func Benchmark_Utils_toLower(b *testing.B) {
var path = "/RePos/GoFiBer/FibEr/iSsues/187643/CoMmEnts"
var res string
for n := 0; n < b.N; n++ {
res = toLower(path)
}
assertEqual(b, "/repos/gofiber/fiber/issues/187643/comments", res)
}
func Benchmark_Utils_toUpper(b *testing.B) {
var path = "/RePos/GoFiBer/FibEr/iSsues/187643/CoMmEnts"
var res string
for n := 0; n < b.N; n++ {
res = toUpper(path)
}
assertEqual(b, "/REPOS/GOFIBER/FIBER/ISSUES/187643/COMMENTS", res)
}