diff options
| author | 1911860538 <alxps1911@gmail.com> | 2025-09-15 14:39:58 +0000 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2025-09-15 17:34:45 -0700 |
| commit | e3ed0fbe6a4c7c5e91a4a82c1bcbc96b9ac37016 (patch) | |
| tree | 8f8bfcf669f5b00a6bbc3e0b43edb6d950e7c777 /src/cmd/internal/script | |
| parent | 10bfddc91deac9d28817fca6ea0d2a0e520e9581 (diff) | |
| download | go-e3ed0fbe6a4c7c5e91a4a82c1bcbc96b9ac37016.tar.xz | |
all: replace strings.Split with strings.SplitSeq
In Go 1.25+, strings.SplitSeq offers better
performance. Here are the benchmark results comparing
strings.Split and strings.SplitSeq in a for-loop, with the
benchmark code located in src/strings/iter_test.go:
goos: darwin
goarch: amd64
pkg: cmd/go/internal/auth
cpu: Intel(R) Core(TM) i7-8569U CPU @ 2.80GHz
│ old.txt │ new.txt │
│ sec/op │ sec/op vs base │
ParseGitAuth/standard-8 281.4n ± 1% 218.0n ± 11% -22.54% (p=0.000 n=10)
ParseGitAuth/with_url-8 549.1n ± 1% 480.5n ± 13% -12.48% (p=0.002 n=10)
ParseGitAuth/minimal-8 235.4n ± 1% 197.3n ± 7% -16.20% (p=0.000 n=10)
ParseGitAuth/complex-8 797.6n ± 2% 805.2n ± 4% ~ (p=0.481 n=10)
ParseGitAuth/empty-8 87.48n ± 3% 63.25n ± 6% -27.71% (p=0.000 n=10)
ParseGitAuth/malformed-8 228.8n ± 1% 171.2n ± 3% -25.17% (p=0.000 n=10)
geomean 288.9n 237.7n -17.72%
│ old.txt │ new.txt │
│ B/op │ B/op vs base │
ParseGitAuth/standard-8 192.00 ± 0% 96.00 ± 0% -50.00% (p=0.000 n=10)
ParseGitAuth/with_url-8 400.0 ± 0% 288.0 ± 0% -28.00% (p=0.000 n=10)
ParseGitAuth/minimal-8 144.00 ± 0% 80.00 ± 0% -44.44% (p=0.000 n=10)
ParseGitAuth/complex-8 528.0 ± 0% 400.0 ± 0% -24.24% (p=0.000 n=10)
ParseGitAuth/empty-8 32.00 ± 0% 16.00 ± 0% -50.00% (p=0.000 n=10)
ParseGitAuth/malformed-8 176.00 ± 0% 80.00 ± 0% -54.55% (p=0.000 n=10)
geomean 179.0 102.1 -42.96%
│ old.txt │ new.txt │
│ allocs/op │ allocs/op vs base │
ParseGitAuth/standard-8 3.000 ± 0% 2.000 ± 0% -33.33% (p=0.000 n=10)
ParseGitAuth/with_url-8 4.000 ± 0% 3.000 ± 0% -25.00% (p=0.000 n=10)
ParseGitAuth/minimal-8 3.000 ± 0% 2.000 ± 0% -33.33% (p=0.000 n=10)
ParseGitAuth/complex-8 4.000 ± 0% 3.000 ± 0% -25.00% (p=0.000 n=10)
ParseGitAuth/empty-8 2.000 ± 0% 1.000 ± 0% -50.00% (p=0.000 n=10)
ParseGitAuth/malformed-8 3.000 ± 0% 2.000 ± 0% -33.33% (p=0.000 n=10)
geomean 3.086 2.040 -33.91%
Updates #69315.
Change-Id: Id0219edea45d9658d527b863162ebe917e7821d9
GitHub-Last-Rev: 392b315e122f2c9ef8703ca2dbce8f82ec198556
GitHub-Pull-Request: golang/go#75259
Reviewed-on: https://go-review.googlesource.com/c/go/+/701015
Reviewed-by: Keith Randall <khr@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
Reviewed-by: Keith Randall <khr@google.com>
Auto-Submit: Emmanuel Odeke <emmanuel@orijtech.com>
Diffstat (limited to 'src/cmd/internal/script')
| -rw-r--r-- | src/cmd/internal/script/cmds.go | 2 | ||||
| -rw-r--r-- | src/cmd/internal/script/scripttest/conditions.go | 2 |
2 files changed, 2 insertions, 2 deletions
diff --git a/src/cmd/internal/script/cmds.go b/src/cmd/internal/script/cmds.go index 7a930caf35..a682d9b3f6 100644 --- a/src/cmd/internal/script/cmds.go +++ b/src/cmd/internal/script/cmds.go @@ -513,7 +513,7 @@ func lookPath(s *State, command string) (string, error) { } pathEnv, _ := s.LookupEnv(pathEnvName()) - for _, dir := range strings.Split(pathEnv, string(filepath.ListSeparator)) { + for dir := range strings.SplitSeq(pathEnv, string(filepath.ListSeparator)) { if dir == "" { continue } diff --git a/src/cmd/internal/script/scripttest/conditions.go b/src/cmd/internal/script/scripttest/conditions.go index e35ac2ddb7..6702e9279b 100644 --- a/src/cmd/internal/script/scripttest/conditions.go +++ b/src/cmd/internal/script/scripttest/conditions.go @@ -88,7 +88,7 @@ func pieLinkExt(s *script.State) (bool, error) { func hasGodebug(s *script.State, value string) (bool, error) { godebug, _ := s.LookupEnv("GODEBUG") - for _, p := range strings.Split(godebug, ",") { + for p := range strings.SplitSeq(godebug, ",") { if strings.TrimSpace(p) == value { return true, nil } |
