aboutsummaryrefslogtreecommitdiff
path: root/src/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd')
-rw-r--r--src/cmd/compile/internal/test/bench_test.go55
1 files changed, 54 insertions, 1 deletions
diff --git a/src/cmd/compile/internal/test/bench_test.go b/src/cmd/compile/internal/test/bench_test.go
index 694673a8f6..1d74d39a49 100644
--- a/src/cmd/compile/internal/test/bench_test.go
+++ b/src/cmd/compile/internal/test/bench_test.go
@@ -4,7 +4,10 @@
package test
-import "testing"
+import (
+ "fmt"
+ "testing"
+)
var globl int64
var globl32 int32
@@ -174,3 +177,53 @@ func BenchmarkSimplifyNegDiv(b *testing.B) {
globl = s
}
}
+
+var globbool bool
+
+// containsRight compares strs[i] == str (slice element on left).
+//
+//go:noinline
+func containsRight(strs []string, str string) bool {
+ for i := range strs {
+ if strs[i] == str {
+ return true
+ }
+ }
+ return false
+}
+
+// containsLeft compares str == strs[i] (parameter on left).
+//
+//go:noinline
+func containsLeft(strs []string, str string) bool {
+ for i := range strs {
+ if str == strs[i] {
+ return true
+ }
+ }
+ return false
+}
+
+// BenchmarkStringEqParamOrder tests that the operand order of string
+// equality comparisons does not affect performance. See issue #74471.
+func BenchmarkStringEqParamOrder(b *testing.B) {
+ strs := []string{
+ "12312312", "abcsdsfw", "abcdefgh", "qereqwre",
+ "gwertdsg", "hellowod", "iamgroot", "theiswer",
+ "dg323sdf", "gadsewwe", "g42dg4t3", "4hre2323",
+ "23eg4325", "13234234", "32dfgsdg", "23fgre34",
+ "43rerrer", "hh2s2443", "hhwesded", "1swdf23d",
+ "gwcdrwer", "bfgwertd", "badgwe3g", "lhoejyop",
+ }
+ target := fmt.Sprintf("%s", "notfound")
+ b.Run("ParamRight", func(b *testing.B) {
+ for b.Loop() {
+ globbool = containsRight(strs, target)
+ }
+ })
+ b.Run("ParamLeft", func(b *testing.B) {
+ for b.Loop() {
+ globbool = containsLeft(strs, target)
+ }
+ })
+}