tests for thier3 - works and very fast

This commit is contained in:
Richard Thier 2025-09-29 18:18:37 +02:00
parent 86f81d2a1c
commit 7ca9a19c5d
2 changed files with 13 additions and 1 deletions

View File

@ -91,7 +91,7 @@ static inline void thiersort2(uint32_t *arr, uint32_t *temparr, int n, sch_rand_
} }
/* arr -> temparr */ /* arr -> temparr */
/* Move to the buckets - backwards going save a few cache miss */ /* Move to the buckets */
/* Rem.: This also changes bucket[i] so they will point to bucket beginnings */ /* Rem.: This also changes bucket[i] so they will point to bucket beginnings */
#pragma GCC unroll 64 #pragma GCC unroll 64
for(int i = 0; i < n; ++i) { for(int i = 0; i < n; ++i) {

View File

@ -22,6 +22,7 @@
#include "qsort/schwab_sort.h" #include "qsort/schwab_sort.h"
#include "qsort/chatgpt_qs.h" #include "qsort/chatgpt_qs.h"
#include "threepass.h" #include "threepass.h"
#include "thiersort3.h"
// #define MAGYAR_SORT_DEFAULT_REUSE // #define MAGYAR_SORT_DEFAULT_REUSE
#include "magyarsort.h" #include "magyarsort.h"
@ -219,6 +220,13 @@ static inline void do_thier2(uint32_t *a, int n) noexcept {
thiersort2(a, &(tmp[0]), n, &state); thiersort2(a, &(tmp[0]), n, &state);
} }
/** thier3 */
static inline void do_thier3(uint32_t *a, int n) noexcept {
assert(n * uint32_t(sizeof(a[0])) <= INT_MAX);
std::vector<uint32_t> tmp(n);
thiersort3(a, &(tmp[0]), n);
}
/** 3+1 pass bottom-up radix */ /** 3+1 pass bottom-up radix */
static inline void do_threepass(uint32_t *a, int n) noexcept { static inline void do_threepass(uint32_t *a, int n) noexcept {
threepass(a, n); threepass(a, n);
@ -999,6 +1007,10 @@ int main(int argc, char **argv) {
measure(inputtype, "thier2", [&] { do_thier2(&w[0], w.size()); }); measure(inputtype, "thier2", [&] { do_thier2(&w[0], w.size()); });
assert(w == expected); assert(w == expected);
w = v;
measure(inputtype, "thier3", [&] { do_thier3(&w[0], w.size()); });
assert(w == expected);
w = v; w = v;
measure(inputtype, "threep", [&] { do_threepass(&w[0], w.size()); }); measure(inputtype, "threep", [&] { do_threepass(&w[0], w.size()); });
assert(w == expected); assert(w == expected);