aboutsummaryrefslogtreecommitdiff
path: root/test/codegen/strings.go
diff options
context:
space:
mode:
authorYoulin Feng <fengyoulin@live.com>2025-09-04 09:08:14 +0800
committerGopher Robot <gobot@golang.org>2025-09-09 12:10:07 -0700
commita5fa5ea51cd8fd9bcb8230d2accf9d55826f76b3 (patch)
treef1966aae45ec96a4c378aef6b1ebfbe357a6ffab /test/codegen/strings.go
parent4c63d798cb947a3cdd5a5b68f254a73d83eb288f (diff)
downloadgo-a5fa5ea51cd8fd9bcb8230d2accf9d55826f76b3.tar.xz
cmd/compile/internal/ssa: expand runtime.memequal for length {3,5,6,7}
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 <khr@golang.org> Reviewed-by: Keith Randall <khr@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Mark Freeman <markfreeman@google.com> Auto-Submit: Keith Randall <khr@golang.org>
Diffstat (limited to 'test/codegen/strings.go')
-rw-r--r--test/codegen/strings.go22
1 files changed, 22 insertions, 0 deletions
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")
+}