From 51bdd3bdcc016fe85add6ce912a0c3075e3a6d47 Mon Sep 17 00:00:00 2001 From: cui fliter Date: Sun, 8 Oct 2023 10:51:45 +0800 Subject: [PATCH] os: use strings.EqualFold in os_test.go strings.EqualFold has no memory overhead and has better performance than strings.ToLower. This is a performance test: package bench import ( "strings" "testing" ) func BenchmarkToLower(b *testing.B) { str1 := "Windows" str2 := "windows" for i := 0; i < b.N; i++ { if strings.ToLower(str1) == strings.ToLower(str2) { } } } func BenchmarkEqualFold(b *testing.B) { str1 := "Windows" str2 := "windows" for i := 0; i < b.N; i++ { if strings.EqualFold(str1, str2) { } } } The result: goos: darwin goarch: arm64 BenchmarkToLower-8 31404808 36.99 ns/op 8 B/op 1 allocs/op BenchmarkEqualFold-8 194780793 5.989 ns/op 0 B/op 0 allocs/op PASS Change-Id: Id3d92534942d3eb0bdc1d01359324030ad0e434f Reviewed-on: https://go-review.googlesource.com/c/go/+/533635 Run-TryBot: shuang cui Reviewed-by: Ian Lance Taylor Auto-Submit: Ian Lance Taylor Reviewed-by: Dmitri Shuralyov Reviewed-by: qiulaidongfeng <2645477756@qq.com> TryBot-Result: Gopher Robot --- src/os/os_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/os/os_test.go b/src/os/os_test.go index da70c398e8..ae12b9ce1b 100644 --- a/src/os/os_test.go +++ b/src/os/os_test.go @@ -147,7 +147,7 @@ func size(name string, t *testing.T) int64 { func equal(name1, name2 string) (r bool) { switch runtime.GOOS { case "windows": - r = strings.ToLower(name1) == strings.ToLower(name2) + r = strings.EqualFold(name1, name2) default: r = name1 == name2 } -- 2.48.1