From a5fa5ea51cd8fd9bcb8230d2accf9d55826f76b3 Mon Sep 17 00:00:00 2001 From: Youlin Feng Date: Thu, 4 Sep 2025 09:08:14 +0800 Subject: cmd/compile/internal/ssa: expand runtime.memequal for length {3,5,6,7} MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This CL slightly speeds up strings.HasPrefix when testing constant prefixes of length {3,5,6,7}. goos: linux goarch: amd64 cpu: Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz │ old │ new │ │ sec/op │ sec/op vs base │ StringPrefix3-8 11.125n ± 2% 8.539n ± 1% -23.25% (p=0.000 n=20) StringPrefix5-8 11.170n ± 2% 8.700n ± 1% -22.11% (p=0.000 n=20) StringPrefix6-8 11.190n ± 2% 8.655n ± 1% -22.65% (p=0.000 n=20) StringPrefix7-8 11.095n ± 1% 8.878n ± 1% -19.98% (p=0.000 n=20) Change-Id: I510a80d59cf78680b57d68780d35d212d24030e2 Reviewed-on: https://go-review.googlesource.com/c/go/+/700816 Reviewed-by: Keith Randall Reviewed-by: Keith Randall LUCI-TryBot-Result: Go LUCI Reviewed-by: Mark Freeman Auto-Submit: Keith Randall --- test/codegen/strings.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'test/codegen/strings.go') diff --git a/test/codegen/strings.go b/test/codegen/strings.go index fbcef57cd1..498c3d398f 100644 --- a/test/codegen/strings.go +++ b/test/codegen/strings.go @@ -6,6 +6,8 @@ package codegen +import "strings" + // This file contains code generation tests related to the handling of // string types. @@ -89,3 +91,23 @@ func NotEqualSelf(s string) bool { } var bsink []byte + +func HasPrefix3(s string) bool { + // amd64:-`.*memequal.*` + return strings.HasPrefix(s, "str") +} + +func HasPrefix5(s string) bool { + // amd64:-`.*memequal.*` + return strings.HasPrefix(s, "strin") +} + +func HasPrefix6(s string) bool { + // amd64:-`.*memequal.*` + return strings.HasPrefix(s, "string") +} + +func HasPrefix7(s string) bool { + // amd64:-`.*memequal.*` + return strings.HasPrefix(s, "strings") +} -- cgit v1.3