-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathslicetostring_benchmark_test.go
69 lines (60 loc) · 2.14 KB
/
slicetostring_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
63
64
65
66
67
68
69
package stringFormatter_test
import (
"fmt"
"github.com/wissance/stringFormatter"
"testing"
)
func BenchmarkSliceToStringAdvancedWith8IntItems(b *testing.B) {
slice := []any{100, 200, 300, 400, 500, 600, 700, 800}
separator := ","
for i := 0; i < b.N; i++ {
_ = stringFormatter.SliceToString(&slice, &separator)
}
}
func BenchmarkSliceStandard8IntItems(b *testing.B) {
slice := []any{100, 200, 300, 400, 500, 600, 700, 800}
for i := 0; i < b.N; i++ {
_ = fmt.Sprintf("%+q", slice)
}
}
func BenchmarkSliceToStringAdvanced10MixedItems(b *testing.B) {
slice := []any{100, "200", 300, "400", 500, 600, "700", 800, 1.09, "hello"}
separator := ","
for i := 0; i < b.N; i++ {
_ = stringFormatter.SliceToString(&slice, &separator)
}
}
func BenchmarkSliceToStringAdvanced10TypedItems(b *testing.B) {
slice := []int32{100, 102, 300, 404, 500, 600, 707, 800, 909, 1024}
for i := 0; i < b.N; i++ {
_ = stringFormatter.Format("{0:L,}", []any{slice})
}
}
func BenchmarkSliceStandard10MixedItems(b *testing.B) {
slice := []any{100, "200", 300, "400", 500, 600, "700", 800, 1.09, "hello"}
for i := 0; i < b.N; i++ {
_ = fmt.Sprintf("%+q", slice)
}
}
func BenchmarkSliceToStringAdvanced20StrItems(b *testing.B) {
slice := []any{"str1", "str2", "str3", "str4", "str5", "str6", "str7", "str8", "str9", "str10",
"str11", "str12", "str13", "str14", "str15", "str16", "str17", "str18", "str19", "str20"}
for i := 0; i < b.N; i++ {
_ = stringFormatter.Format("{0:L,}", []any{slice})
}
}
func BenchmarkSliceToStringAdvanced20TypedStrItems(b *testing.B) {
slice := []string{"str1", "str2", "str3", "str4", "str5", "str6", "str7", "str8", "str9", "str10",
"str11", "str12", "str13", "str14", "str15", "str16", "str17", "str18", "str19", "str20"}
separator := ","
for i := 0; i < b.N; i++ {
_ = stringFormatter.SliceSameTypeToString(&slice, &separator)
}
}
func BenchmarkSliceStandard20StrItems(b *testing.B) {
slice := []any{"str1", "str2", "str3", "str4", "str5", "str6", "str7", "str8", "str9", "str10",
"str11", "str12", "str13", "str14", "str15", "str16", "str17", "str18", "str19", "str20"}
for i := 0; i < b.N; i++ {
_ = fmt.Sprintf("%+q", slice)
}
}