4 ms·
The change mentioned at the top of the post (https://go-review.googlesource.com/c/exp/+/378134 https://go-review.googlesource.com/c/exp/+/378134) also has a ben
by eliben 5y ago
The change mentioned at the top of the post (https://go-review.googlesource.com/c/exp/+/378134 https://go-review.googlesource.com/c/exp/+/378134) also has a benchmark to compare sorting structs using sort.Slice vs a new generic approach that uses a comparison function:
name old time/op new time/op delta
SortStructs-8 18.6ms ± 2% 15.9ms ± 3% -14.43% (p=0.000 n=10+10)
14.4% is the speedup of the generic version.
The article explains why this happens (towards the end).
- tedunangst 5y agoUnsolicited commentary: I think my commitment to a thorough reading was limited by my interest in the performance of bubble sort. On the other hand, the code for sort.Search also fits in a blog post, and it's a function I have called inside a loop.
- eliben 5y agoThat's a good point, thank you for bringing it up. Finding the right examples is really tricky. sort.Search is binary search and hence a bit tricky to benchmark properly because of how ridiculously fast it is. Only a handful of comparison calls are made even for huge slices.