Closed
Description
What version of Go are you using (go version
)?
go version devel go1.21-4f467f1082 Wed Jan 25 21:16:32 2023 +0000 linux/amd64
What did you do?
I benchmarked two binary searches on an array of strings:
sort.Search(len(strs), func(i int) bool { return key <= strs[i] })
slices.BinarySearchFunc(strs, key, strings.Compare)
Turns out the former can be significantly faster. Seeing how strings.Compare is implemented, I get why:
Lines 7 to 28 in d42c08a
Should the decision to not optimize strings.Compare be reconsidered? Even if not, should its comments be changed to not recommend against its use? Because it appears to me as the sane way to work with strings and x/exp/slices.