Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qsort: add benchmarks from the standard library #77

Merged
merged 2 commits into from Apr 26, 2022

Conversation

kevinburkesegment
Copy link
Contributor

These will let us be more confident that the qsort makes sense to use,
especially when e.g. the Go standard library introduces a new sorting
algorithm, we can compare the two.

On my Mac, using the pdqsort from Go 1.19, the relevant timings are:

Sort8/100000-10             4.91ms ± 0%
Sort8/1000000-10            60.1ms ± 0%
StdlibSort8/100000-10       8.16ms ± 0%
StdlibSort8/1000000-10       103ms ± 0%

Sort8/100000-10            163MB/s ± 0%
Sort8/1000000-10           133MB/s ± 0%
StdlibSort8/100000-10     98.0MB/s ± 0%
StdlibSort8/1000000-10    77.5MB/s ± 0%

Compared to the Go 1.18 sort algorithm:

Sort8/100000-10             4.90ms ± 0%
Sort8/1000000-10            59.0ms ± 0%
StdlibSort8/100000-10       8.53ms ± 0%
StdlibSort8/1000000-10       105ms ± 0%

Sort8/100000-10            163MB/s ± 0%
Sort8/1000000-10           136MB/s ± 0%
StdlibSort8/100000-10     93.8MB/s ± 0%
StdlibSort8/1000000-10    76.0MB/s ± 0%

So the Go standard library sort performance is improving but we are
still about 40% faster than the benchmark.

These will let us be more confident that a custom sort algorithm makes
sense to use, especially when e.g. the Go standard library introduces
a new sorting algorithm, we can compare the two.

On my Mac, using the pdqsort from Go 1.19, the relevant timings are:

    Sort8/100000-10             4.91ms ± 0%
    Sort8/1000000-10            60.1ms ± 0%
    StdlibSort8/100000-10       8.16ms ± 0%
    StdlibSort8/1000000-10       103ms ± 0%

    Sort8/100000-10            163MB/s ± 0%
    Sort8/1000000-10           133MB/s ± 0%
    StdlibSort8/100000-10     98.0MB/s ± 0%
    StdlibSort8/1000000-10    77.5MB/s ± 0%

Compared to the Go 1.18 sort algorithm:

    Sort8/100000-10             4.90ms ± 0%
    Sort8/1000000-10            59.0ms ± 0%
    StdlibSort8/100000-10       8.53ms ± 0%
    StdlibSort8/1000000-10       105ms ± 0%

    Sort8/100000-10            163MB/s ± 0%
    Sort8/1000000-10           136MB/s ± 0%
    StdlibSort8/100000-10     93.8MB/s ± 0%
    StdlibSort8/1000000-10    76.0MB/s ± 0%

So the Go standard library sort performance is improving but we are
still about 40% faster than the benchmark.
@kevinburkesegment kevinburkesegment force-pushed the sort-benchmark branch 3 times, most recently from bc0e2c1 to f884d76 Compare April 26, 2022 20:54
@achille-roussel
Copy link
Contributor

achille-roussel commented Apr 26, 2022

For completeness, adding a snapshot for a run on a x86:

goos: linux
goarch: amd64
pkg: github.com/segmentio/asm/qsort
cpu: Intel(R) Xeon(R) CPU @ 2.60GHz

BenchmarkSort8/100000
BenchmarkSort8/100000   	     625	   1916996 ns/op	 417.32 MB/s
BenchmarkSort8/1000000
BenchmarkSort8/1000000  	      49	  24289400 ns/op	 329.36 MB/s

BenchmarkStdlibSort8/100000
BenchmarkStdlibSort8/100000         	      86	  11709887 ns/op	  68.32 MB/s
BenchmarkStdlibSort8/1000000
BenchmarkStdlibSort8/1000000        	       7	 144533331 ns/op	  55.35 MB/s

@kevinburkesegment kevinburkesegment force-pushed the sort-benchmark branch 2 times, most recently from 38cab90 to a2379cd Compare April 26, 2022 22:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants