forked from erikdubbelboer/fasthttp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uri_timing_test.go
49 lines (40 loc) · 1.14 KB
/
uri_timing_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
package fasthttp
import (
"testing"
)
func BenchmarkURIParsePath(b *testing.B) {
benchmarkURIParse(b, "google.com", "/foo/bar")
}
func BenchmarkURIParsePathQueryString(b *testing.B) {
benchmarkURIParse(b, "google.com", "/foo/bar?query=string&other=value")
}
func BenchmarkURIParsePathQueryStringHash(b *testing.B) {
benchmarkURIParse(b, "google.com", "/foo/bar?query=string&other=value#hashstring")
}
func BenchmarkURIParseHostname(b *testing.B) {
benchmarkURIParse(b, "google.com", "http://foobar.com/foo/bar?query=string&other=value#hashstring")
}
func BenchmarkURIFullURI(b *testing.B) {
host := []byte("foobar.com")
requestURI := []byte("/foobar/baz?aaa=bbb&ccc=ddd")
uriLen := len(host) + len(requestURI) + 7
b.RunParallel(func(pb *testing.PB) {
var u URI
u.Parse(host, requestURI)
for pb.Next() {
uri := u.FullURI()
if len(uri) != uriLen {
b.Fatalf("unexpected uri len %d. Expecting %d", len(uri), uriLen)
}
}
})
}
func benchmarkURIParse(b *testing.B, host, uri string) {
strHost, strURI := []byte(host), []byte(uri)
b.RunParallel(func(pb *testing.PB) {
var u URI
for pb.Next() {
u.Parse(strHost, strURI)
}
})
}