Skip to content

Commit a5206e4

Browse files
committed
benchmarks on slicetostr func
1 parent adab32a commit a5206e4

File tree

3 files changed

+60
-3
lines changed

3 files changed

+60
-3
lines changed

img/slice2str_benchmarks.png

151 KB
Loading

slicetostring_benchmark_test.go

+54-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,54 @@
1-
package stringFormatter
1+
package stringFormatter_test
2+
3+
import (
4+
"fmt"
5+
"github.com/wissance/stringFormatter"
6+
"testing"
7+
)
8+
9+
func BenchmarkSliceToStringAdvancedWith8IntItems(b *testing.B) {
10+
slice := []any{100, 200, 300, 400, 500, 600, 700, 800}
11+
separator := ","
12+
for i := 0; i < b.N; i++ {
13+
_ = stringFormatter.SliceToString(&slice, &separator)
14+
}
15+
}
16+
17+
func BenchmarkSliceStandard8IntItems(b *testing.B) {
18+
slice := []any{100, 200, 300, 400, 500, 600, 700, 800}
19+
for i := 0; i < b.N; i++ {
20+
_ = fmt.Sprintf("%+q", slice)
21+
}
22+
}
23+
24+
func BenchmarkSliceToStringAdvanced10MixedItems(b *testing.B) {
25+
slice := []any{100, "200", 300, "400", 500, 600, "700", 800, 1.09, "hello"}
26+
separator := ","
27+
for i := 0; i < b.N; i++ {
28+
_ = stringFormatter.SliceToString(&slice, &separator)
29+
}
30+
}
31+
32+
func BenchmarkSliceStandard10MixedItems(b *testing.B) {
33+
slice := []any{100, "200", 300, "400", 500, 600, "700", 800, 1.09, "hello"}
34+
for i := 0; i < b.N; i++ {
35+
_ = fmt.Sprintf("%+q", slice)
36+
}
37+
}
38+
39+
func BenchmarkSliceToStringAdvanced20StrItems(b *testing.B) {
40+
slice := []any{"str1", "str2", "str3", "str4", "str5", "str6", "str7", "str8", "str9", "str10",
41+
"str11", "str12", "str13", "str14", "str15", "str16", "str17", "str18", "str19", "str20"}
42+
separator := ","
43+
for i := 0; i < b.N; i++ {
44+
_ = stringFormatter.SliceToString(&slice, &separator)
45+
}
46+
}
47+
48+
func BenchmarkSliceStandard20StrItems(b *testing.B) {
49+
slice := []any{"str1", "str2", "str3", "str4", "str5", "str6", "str7", "str8", "str9", "str10",
50+
"str11", "str12", "str13", "str14", "str15", "str16", "str17", "str18", "str19", "str20"}
51+
for i := 0; i < b.N; i++ {
52+
_ = fmt.Sprintf("%+q", slice)
53+
}
54+
}

utils/run_benchamrks.ps1

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
$root_dir = Resolve-Path -Path ".."
2-
echo "******** 1. standadrd fmt formatting lib benchmarks ******** "
2+
echo "******** 1. standard fmt formatting lib benchmarks ******** "
33
go test $root_dir -bench=Fmt -benchmem -cpu 1
44
echo "******** 2. stringFormatter lib benchmarks ******** "
5-
go test $root_dir -bench=Format -benchmem -cpu 1
5+
go test $root_dir -bench=Format -benchmem -cpu 1
6+
echo "******** 3. slice fmt benchmarks ******** "
7+
go test $root_dir -bench=SliceStandard -benchmem -cpu 1
8+
echo "******** 4. stringFormatter lib benchmarks ******** "
9+
go test $root_dir -bench=SliceToStringAdvanced -benchmem -cpu 1

0 commit comments

Comments
 (0)