Skip to content
go implementation of pattern defeating quicksort
Go Makefile Shell
Branch: master
Clone or download
Latest commit ef4ab31 Jul 21, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.travis.yml
Makefile Add coverage report Jul 21, 2019
README.md
go.mod
go.sum
pdqsort.go
pdqsort_test.go
profile.sh Add script to help profile Jun 13, 2019

README.md

go-pdqsort

Build Status codecov

Pattern-defeating sort is a new variants of hybrid sort discovered in 2016, the first proof of concept was in C++ and later ported to rust. It is now part of rust standard libarary for unstable sort.

This library is to implement pattern-defeating sort in pure go.

Benchmark

Sort 1000 of Integers

  • pdqsort
BenchmarkPDQSortInt1K-4   	   20000	     80874 ns/op	      32 B/op	       1 allocs/op
  • sort from standard library
BenchmarkStdSortInt1K-4   	   20000	     69828 ns/op	      32 B/op	       1 allocs/op

The sorting algorithm in the standard library is also in hybrid approach. It would go by shell sort on small input, and partition by quicksort up to a certain recursive depth, then change to heapsort for better worst case scenario.

From the result the pattern defeating sort is much slower than the sort from standrad library. It is expected since go's memory layout is mainly heap managed and it is very different from what's in C++ and Rust. Therefore the key invention from pdqsort to reduce the cpu branch prediction is not impactful on speed, and slowing down due to more memory access.

You can’t perform that action at this time.