1
0
mirror of https://github.com/golang/go synced 2024-11-20 10:54:49 -07:00
go/src/pkg/sort
David Symonds 78cee8b3bb sort: use fewer comparisons when choosing pivot.
This is based on rsc's code posted to issue 2585.

Benchmark results are greatly improved:
        benchmark                old ns/op    new ns/op    delta
        BenchmarkSortString1K       564397       445897  -21.00%
        BenchmarkSortInt1K          270889       221249  -18.32%
        BenchmarkSortInt64K       26850765     21351967  -20.48%

Eyeballing a sampling of the raw number of comparisons shows a drop
on the order of 20-30% almost everywhere. The test input data that
doesn't match that are some of sawtooth/rand/plateau distributions,
where there is no change in the number of comparisons; that is,
there are no situations where this makes *more* comparisons.

Fixes #2585.

R=iant, rsc
CC=golang-dev
https://golang.org/cl/7306098
2013-02-14 15:04:22 +11:00
..
example_interface_test.go sort: add interface examples 2012-02-16 13:16:07 +11:00
example_test.go sort: add Reverse as a function 2013-02-01 08:44:45 -08:00
export_test.go
search_test.go
search.go sort: fix comment for various Search routines 2012-11-07 05:07:46 +08:00
sort_test.go sort: use fewer comparisons when choosing pivot. 2013-02-14 15:04:22 +11:00
sort.go sort: use fewer comparisons when choosing pivot. 2013-02-14 15:04:22 +11:00