Skip to content

Commit e278a78

Browse files
committed
path: add Join benchmark
This is a case where CL 653856 saves an allocation. │ old │ new │ │ sec/op │ sec/op vs base │ Join-24 73.57n ± 1% 60.27n ± 1% -18.07% (p=0.000 n=10) │ old │ new │ │ B/op │ B/op vs base │ Join-24 48.00 ± 0% 24.00 ± 0% -50.00% (p=0.000 n=10) │ old │ new │ │ allocs/op │ allocs/op vs base │ Join-24 2.000 ± 0% 1.000 ± 0% -50.00% (p=0.000 n=10) Change-Id: I56308262ca73a7ab9698b54fd8681f5b44626995 Reviewed-on: https://go-review.googlesource.com/c/go/+/665075 Reviewed-by: Keith Randall <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Cherry Mui <[email protected]>
1 parent 80bff42 commit e278a78

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/path/path_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package path_test
66

77
import (
8+
"path"
89
. "path"
910
"runtime"
1011
"testing"
@@ -234,3 +235,14 @@ func TestIsAbs(t *testing.T) {
234235
}
235236
}
236237
}
238+
239+
func BenchmarkJoin(b *testing.B) {
240+
b.ReportAllocs()
241+
parts := []string{"one", "two", "three", "four"}
242+
s := parts[0]
243+
for b.Loop() {
244+
parts[0] = s
245+
s = path.Join(parts...)
246+
s = s[:3]
247+
}
248+
}

0 commit comments

Comments
 (0)