From e278a789b61ffbdf4f6ca8accf43ab04148cd551 Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Fri, 11 Apr 2025 16:35:13 -0700 Subject: [PATCH] path: add Join benchmark MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 LUCI-TryBot-Result: Go LUCI Reviewed-by: Cherry Mui --- src/path/path_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/path/path_test.go b/src/path/path_test.go index a57286f6b8..6bd7a2cdad 100644 --- a/src/path/path_test.go +++ b/src/path/path_test.go @@ -5,6 +5,7 @@ package path_test import ( + "path" . "path" "runtime" "testing" @@ -234,3 +235,14 @@ func TestIsAbs(t *testing.T) { } } } + +func BenchmarkJoin(b *testing.B) { + b.ReportAllocs() + parts := []string{"one", "two", "three", "four"} + s := parts[0] + for b.Loop() { + parts[0] = s + s = path.Join(parts...) + s = s[:3] + } +} -- 2.51.0