Skip to content

Commit b638390

Browse files
committed
Add benchmark details
1 parent 7dd0a45 commit b638390

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

strings_bench_test.go renamed to strings_concat_bench_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,54 @@ import (
66
"unsafe"
77
)
88

9+
/*
10+
Benchmark results are in concat_bench.txt
11+
Concat - Our implementation (wrapper around strings.Builder
12+
Join - Using strings.Join
13+
Builder - Directly using strings.Builder
14+
Manual - A very efficient way using manual buffer copy. As of 1.13 is barely faster than our Concat, but we prefer this since it uses standard library
15+
16+
❯ go test -bench=. -benchmem
17+
goos: darwin
18+
goarch: amd64
19+
pkg: github.com/wastedcode/strutils
20+
BenchmarkConcatSmall-16 36458156 27.8 ns/op 3 B/op 1 allocs/op
21+
BenchmarkConcatJoinSmall-16 34108449 34.7 ns/op 3 B/op 1 allocs/op
22+
BenchmarkConcatBuilderSmall-16 35770252 29.8 ns/op 8 B/op 1 allocs/op
23+
BenchmarkConcatManualSmall-16 43085545 25.7 ns/op 3 B/op 1 allocs/op
24+
BenchmarkConcatMid-16 29700308 35.1 ns/op 32 B/op 1 allocs/op
25+
BenchmarkConcatJoinMid-16 25948977 44.1 ns/op 32 B/op 1 allocs/op
26+
BenchmarkConcatBuilderMid-16 13468004 85.5 ns/op 56 B/op 3 allocs/op
27+
BenchmarkConcatManualMid-16 33127766 33.8 ns/op 32 B/op 1 allocs/op
28+
BenchmarkConcatLong-16 22853175 51.6 ns/op 48 B/op 1 allocs/op
29+
BenchmarkConcatJoinLong-16 15723216 73.3 ns/op 48 B/op 1 allocs/op
30+
BenchmarkConcatBuilderLong-16 10799188 109 ns/op 112 B/op 3 allocs/op
31+
BenchmarkConcatManualLong-16 22404008 50.8 ns/op 48 B/op 1 allocs/op
32+
BenchmarkConcatLarge-16 26872747 41.5 ns/op 112 B/op 1 allocs/op
33+
BenchmarkConcatJoinLarge-16 21745833 47.2 ns/op 112 B/op 1 allocs/op
34+
BenchmarkConcatBuilderLarge-16 14940462 74.7 ns/op 192 B/op 2 allocs/op
35+
BenchmarkConcatManualLarge-16 27793780 40.3 ns/op 112 B/op 1 allocs/op
36+
37+
benchstat results
38+
name time/op
39+
ConcatSmall-16 27.4ns ± 5%
40+
ConcatJoinSmall-16 36.6ns ± 8%
41+
ConcatBuilderSmall-16 31.5ns ± 3%
42+
ConcatManualSmall-16 27.1ns ± 4%
43+
ConcatMid-16 38.2ns ± 5%
44+
ConcatJoinMid-16 47.0ns ± 3%
45+
ConcatBuilderMid-16 93.5ns ± 8%
46+
ConcatManualMid-16 36.2ns ± 4%
47+
ConcatLong-16 55.8ns ± 8%
48+
ConcatJoinLong-16 79.7ns ± 8%
49+
ConcatBuilderLong-16 114ns ± 7%
50+
ConcatManualLong-16 54.7ns ± 3%
51+
ConcatLarge-16 44.5ns ± 5%
52+
ConcatJoinLarge-16 49.6ns ±10%
53+
ConcatBuilderLarge-16 78.1ns ± 0%
54+
ConcatManualLarge-16 42.3ns ± 1%
55+
*/
56+
957
var concatResult string
1058

1159
func concatStringsJoin(strs ...string) string {

0 commit comments

Comments
 (0)