6f6b2f04b5
- change way of protection from O(N^2) on duplicate values. Previous algorithm does additional comparisons and swaps on every split pass. Changed algorithm does one ordinal quicksort split pass, and if distribution is skewed, then additional pass to separate pivot's duplicates. Changed algorithm could be slower on very ununique slice, but it is still protected from O(N^2). - increase small slice size and do simple shell sort pass to amortize worst case on small slices. Small slice has higher probability to have skewed distribution, so lets sort it with simpler algorithm. benchmark old ns/op new ns/op delta BenchmarkSortString1K 458374 388641 -15.21% BenchmarkSortInt1K 217851 181796 -16.55% BenchmarkSortInt64K 20539264 16730340 -18.54% BenchmarkSort1e2 98668 95554 -3.16% BenchmarkSort1e4 20278500 18316829 -9.67% BenchmarkSort1e6 3215724392 2795999911 -13.05% number of operations: Size: Total: Swap: Less: % % % Sort 100 Avg -5.98% -18.43% -1.90% Sort 100 Max -14.43% -16.02% -4.51% Sort 300 Avg -7.50% -12.76% -5.96% Sort 300 Max -11.29% -9.60% -4.30% Sort 1000 Avg -12.13% -11.65% -12.25% Sort 1000 Max -13.81% -11.77% -11.89% Sort 3000 Avg -14.61% -9.30% -15.86% Sort 3000 Max -15.81% -8.66% -15.19% Sort 10000 Avg -16.10% -8.47% -17.80% Sort 10000 Max -17.13% -7.63% -16.97% Sort 30000 Avg -17.46% -7.56% -19.57% Sort 30000 Max -18.24% -7.62% -17.68% Sort 100000 Avg -18.83% -6.64% -21.33% Sort 100000 Max -19.72% -6.70% -20.96% Sort 300000 Avg -19.61% -6.16% -22.30% Sort 300000 Max -20.69% -6.15% -21.81% Sort 1000000 Avg -20.42% -5.58% -23.31% Sort 1000000 Max -21.54% -5.56% -23.61% Change-Id: I23868e8b52b5841b358cd5403967c9a97871e4d5 Reviewed-on: https://go-review.googlesource.com/15688 Reviewed-by: Russ Cox <rsc@golang.org> |
||
---|---|---|
api | ||
doc | ||
lib/time | ||
misc | ||
src | ||
test | ||
.gitattributes | ||
.gitignore | ||
AUTHORS | ||
CONTRIBUTING.md | ||
CONTRIBUTORS | ||
favicon.ico | ||
LICENSE | ||
PATENTS | ||
README.md | ||
robots.txt |
The Go Programming Language
Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.
For documentation about how to install and use Go, visit https://golang.org/ or load doc/install-source.html in your web browser.
Our canonical Git repository is located at https://go.googlesource.com/go. There is a mirror of the repository at https://github.com/golang/go.
Go is the work of hundreds of contributors. We appreciate your help!
To contribute, please read the contribution guidelines: https://golang.org/doc/contribute.html
Note that we do not accept pull requests and that we use the issue tracker for bug reports and proposals only. Please ask questions on https://forum.golangbridge.org or https://groups.google.com/forum/#!forum/golang-nuts.
Unless otherwise noted, the Go source files are distributed under the BSD-style license found in the LICENSE file.
--
Binary Distribution Notes
If you have just untarred a binary Go distribution, you need to set the environment variable $GOROOT to the full path of the go directory (the one containing this file). You can omit the variable if you unpack it into /usr/local/go, or if you rebuild from sources by running all.bash (see doc/install-source.html). You should also add the Go binary directory $GOROOT/bin to your shell's path.
For example, if you extracted the tar file into $HOME/go, you might put the following in your .profile:
export GOROOT=$HOME/go
export PATH=$PATH:$GOROOT/bin
See https://golang.org/doc/install or doc/install.html for more details.