]> Cypherpunks repositories - gostls13.git/commit
sort: use fewer comparisons when choosing pivot.
authorDavid Symonds <dsymonds@golang.org>
Thu, 14 Feb 2013 04:04:22 +0000 (15:04 +1100)
committerDavid Symonds <dsymonds@golang.org>
Thu, 14 Feb 2013 04:04:22 +0000 (15:04 +1100)
commit78cee8b3bbf4173af79a4d02a26bbe8bea1cd175
treeea614d8fe4fe7881e84144feab24de403fd936f0
parent7f284f85f908909a498663d54da689e56cd38e73
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
src/pkg/sort/sort.go
src/pkg/sort/sort_test.go