-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathconvert_test.go
63 lines (54 loc) · 1.48 KB
/
convert_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
// ⚡️ 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 utils
import "testing"
func Test_Utils_GetString(t *testing.T) {
t.Parallel()
res := GetString([]byte("Hello, World!"))
AssertEqual(t, "Hello, World!", res)
}
// go test -v -run=^$ -bench=GetString -benchmem -count=2
func Benchmark_GetString(b *testing.B) {
var hello = []byte("Hello, World!")
var res string
b.Run("unsafe", func(b *testing.B) {
for n := 0; n < b.N; n++ {
res = GetString(hello)
}
AssertEqual(b, "Hello, World!", res)
})
b.Run("default", func(b *testing.B) {
for n := 0; n < b.N; n++ {
res = string(hello)
}
AssertEqual(b, "Hello, World!", res)
})
}
func Test_Utils_GetBytes(t *testing.T) {
t.Parallel()
res := GetBytes("Hello, World!")
AssertEqual(t, []byte("Hello, World!"), res)
}
// go test -v -run=^$ -bench=GetBytes -benchmem -count=4
func Benchmark_GetBytes(b *testing.B) {
var hello = "Hello, World!"
var res []byte
b.Run("unsafe", func(b *testing.B) {
for n := 0; n < b.N; n++ {
res = GetBytes(hello)
}
AssertEqual(b, []byte("Hello, World!"), res)
})
b.Run("default", func(b *testing.B) {
for n := 0; n < b.N; n++ {
res = []byte(hello)
}
AssertEqual(b, []byte("Hello, World!"), res)
})
}
func Test_Utils_ImmutableString(t *testing.T) {
t.Parallel()
res := ImmutableString("Hello, World!")
AssertEqual(t, "Hello, World!", res)
}