{"id":20467224,"url":"https://github.com/zhangyunhao116/pdqsort","last_synced_at":"2025-06-13T12:07:55.322Z","repository":{"id":38320341,"uuid":"429647696","full_name":"zhangyunhao116/pdqsort","owner":"zhangyunhao116","description":"Pattern-defeating quicksort in Go with generics(need Go1.18). About 2x ~ 60x faster than the built-in sort package.","archived":false,"fork":false,"pushed_at":"2023-01-17T09:15:32.000Z","size":47,"stargazers_count":116,"open_issues_count":1,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-13T09:11:30.528Z","etag":null,"topics":["go","golang","pdqsort","sort","sorting","sorting-algorithms"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zhangyunhao116.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-11-19T02:41:25.000Z","updated_at":"2025-03-20T08:51:22.000Z","dependencies_parsed_at":"2023-02-10T08:45:44.667Z","dependency_job_id":null,"html_url":"https://github.com/zhangyunhao116/pdqsort","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/zhangyunhao116/pdqsort","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhangyunhao116%2Fpdqsort","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhangyunhao116%2Fpdqsort/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhangyunhao116%2Fpdqsort/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhangyunhao116%2Fpdqsort/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zhangyunhao116","download_url":"https://codeload.github.com/zhangyunhao116/pdqsort/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zhangyunhao116%2Fpdqsort/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259642336,"owners_count":22888991,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","golang","pdqsort","sort","sorting","sorting-algorithms"],"created_at":"2024-11-15T13:27:43.740Z","updated_at":"2025-06-13T12:07:55.290Z","avatar_url":"https://github.com/zhangyunhao116.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pdqsort\n\n\u003e The pdqsort has been merged into the Go standard library since Go 1.19, please use `sort` or `slices` directly instead of this package.\n\u003e\n\u003e issue: https://github.com/golang/go/issues/50154\n\u003e\n\u003e commit: https://github.com/golang/go/commit/72e77a7f41bbf45d466119444307fd3ae996e257\n\nThe algorithm is mainly based on pattern-defeating quicksort by Orson Peters.\n\nCompared to sort.Ints(Go1.18), it is **2x** faster in random slices, and **2x ~ 60x** faster in common patterns.\n\n- Paper: https://arxiv.org/pdf/2106.05123.pdf\n- C++  implementation: https://github.com/orlp/pdqsort\n- Rust implementation: https://docs.rs/pdqsort/latest/pdqsort/\n\n```\nBest        Average     Worst       Memory      Stable      Deterministic\nn           n log n     n log n     log n       No          Yes\n```\n\n\n\n## Features\n\n- **Unstable sort**, may reorder equal elements.\n- Disable the optimization from [BlockQuickSort](https://dl.acm.org/doi/10.1145/3274660), since its poor performance in Go.\n\n\n\n## QuickStart\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/zhangyunhao116/pdqsort\"\n)\n\nfunc main() {\n\tx := []int{3, 1, 2, 4, 5, 9, 8, 7}\n\tpdqsort.Slice(x)\n\tfmt.Printf(\"%v\\n\", x)\n}\n\n```\n\n\n\n## Benchmark\n\nGo version: go1.18-a412b5f0d8 linux/amd64\n\nCPU: Intel 11700k(8C16T)\n\nOS: ubuntu 20.04\n\nMEMORY: 16G x 2 (3200MHz)\n\n```text\nname                          time/op\nRandom/pdqsort_64             1.18µs ± 0%\nRandom/stdsort_64             2.38µs ± 0%\nRandom/pdqsort_256            6.24µs ± 3%\nRandom/stdsort_256            13.2µs ± 7%\nRandom/pdqsort_1024           32.4µs ± 0%\nRandom/stdsort_1024           62.2µs ± 0%\nRandom/pdqsort_4096            149µs ± 0%\nRandom/stdsort_4096            291µs ± 0%\nRandom/pdqsort_65536          3.14ms ± 0%\nRandom/stdsort_65536          6.11ms ± 0%\nSorted/pdqsort_64             94.4ns ± 4%\nSorted/stdsort_64              711ns ± 0%\nSorted/pdqsort_256             171ns ± 1%\nSorted/stdsort_256            3.37µs ± 0%\nSorted/pdqsort_1024            507ns ± 0%\nSorted/stdsort_1024           16.6µs ± 0%\nSorted/pdqsort_4096           1.82µs ± 0%\nSorted/stdsort_4096           78.9µs ± 0%\nSorted/pdqsort_65536          28.2µs ± 0%\nSorted/stdsort_65536          1.73ms ± 0%\nNearlySorted/pdqsort_64        353ns ± 2%\nNearlySorted/stdsort_64        931ns ± 1%\nNearlySorted/pdqsort_256      1.78µs ± 1%\nNearlySorted/stdsort_256      4.99µs ± 1%\nNearlySorted/pdqsort_1024     8.28µs ± 0%\nNearlySorted/stdsort_1024     26.1µs ± 1%\nNearlySorted/pdqsort_4096     38.2µs ± 0%\nNearlySorted/stdsort_4096      117µs ± 1%\nNearlySorted/pdqsort_65536     792µs ± 0%\nNearlySorted/stdsort_65536    2.46ms ± 0%\nReversed/pdqsort_64            113ns ± 1%\nReversed/stdsort_64            845ns ± 0%\nReversed/pdqsort_256           253ns ± 1%\nReversed/stdsort_256          3.69µs ± 0%\nReversed/pdqsort_1024          785ns ± 0%\nReversed/stdsort_1024         17.8µs ± 1%\nReversed/pdqsort_4096         2.89µs ± 0%\nReversed/stdsort_4096         83.7µs ± 0%\nReversed/pdqsort_65536        45.1µs ± 0%\nReversed/stdsort_65536        1.80ms ± 0%\nNearlyReversed/pdqsort_64      435ns ± 2%\nNearlyReversed/stdsort_64     1.33µs ± 1%\nNearlyReversed/pdqsort_256    2.13µs ± 1%\nNearlyReversed/stdsort_256    7.23µs ± 1%\nNearlyReversed/pdqsort_1024   10.6µs ± 1%\nNearlyReversed/stdsort_1024   38.4µs ± 1%\nNearlyReversed/pdqsort_4096   50.2µs ± 1%\nNearlyReversed/stdsort_4096    176µs ± 0%\nNearlyReversed/pdqsort_65536  1.04ms ± 1%\nNearlyReversed/stdsort_65536  3.57ms ± 0%\nMod8/pdqsort_64                345ns ± 2%\nMod8/stdsort_64                949ns ± 1%\nMod8/pdqsort_256              1.02µs ± 1%\nMod8/stdsort_256              3.78µs ± 0%\nMod8/pdqsort_1024             3.13µs ± 2%\nMod8/stdsort_1024             14.3µs ± 0%\nMod8/pdqsort_4096             10.2µs ± 1%\nMod8/stdsort_4096             59.3µs ± 0%\nMod8/pdqsort_65536             190µs ± 2%\nMod8/stdsort_65536            1.00ms ± 0%\nAllEqual/pdqsort_64           89.4ns ± 3%\nAllEqual/stdsort_64            381ns ± 1%\nAllEqual/pdqsort_256           170ns ± 1%\nAllEqual/stdsort_256          1.03µs ± 1%\nAllEqual/pdqsort_1024          507ns ± 0%\nAllEqual/stdsort_1024         3.66µs ± 0%\nAllEqual/pdqsort_4096         1.82µs ± 0%\nAllEqual/stdsort_4096         14.0µs ± 0%\nAllEqual/pdqsort_65536        28.2µs ± 0%\nAllEqual/stdsort_65536         224µs ± 0%\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhangyunhao116%2Fpdqsort","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzhangyunhao116%2Fpdqsort","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzhangyunhao116%2Fpdqsort/lists"}