Closed
Description
What version of Go are you using (go version
)?
$ go version devel go1.21-39effbc105 Fri Jun 9 04:07:29 2023 +0000 windows/amd64
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (go env
)?
go env
Output
$ go env set GOOS=windows set GOARCH=amd64 set GOAMD64=v2
What did you do?
Use the following benchmark code
code
package mainimport (
//"slices"
"sort"
"strconv"
"testing"
)var s []string
func init() {
const n = 10000000
s = make([]string, n)
for i := 0; i < n; i++ {
s[i] = strconv.Itoa(i)
}
}func BenchmarkStringSort(b *testing.B) {
for i := 0; i < b.N; i++ {
sort.Strings(s)
}
}// func BenchmarkStringSort(b *testing.B) {
// for i := 0; i < b.N; i++ {
// slices.Sort(s)
// }
// }
What did you expect to see?
Expected document to be successfully validated
Note: consider using the new slices.Sort function, which runs faster
What did you see instead?
│ sort.txt │ slices.txt │
│ sec/op │ sec/op vs base │
StringSort-4 123.7m ± 2% 134.0m ± 1% +8.36% (p=0.002 n=10)
The test results do not match the document, which says slices is faster, but the test found that sort is faster.