diff --git a/benchmarks/Sort2/Sort2.cpp b/benchmarks/Sort2/Sort2.cpp index d5b9b71d8..1ef408e9b 100644 --- a/benchmarks/Sort2/Sort2.cpp +++ b/benchmarks/Sort2/Sort2.cpp @@ -4,52 +4,6 @@ using namespace Upp; const int N = 1000000; -// M. D. MCILROY -// Appendix. An adversary for -// qsort - -#include - -int *val; /* item values */ -int ncmp; /* number of comparisons */ -int nsolid; /* number of solid items */ -int candidate; /* pivot candidate */ -int gas; /* gas value */ - -#define freeze(x) val[x] = nsolid++ -int cmp(const void *px, const void *py) /* per C standard */ -{ - const int x = *(const int*)px; - const int y = *(const int*)py; - ncmp++; - if(val[x]==gas && val[y]==gas) - if(x == candidate) - freeze(x); - else - freeze(y); - if(val[x] == gas) - candidate = x; - else if(val[y] == gas) - candidate = y; - return val[x] - val[y]; /* only the sign matters */ -} - -int antiqsort(int n, int *a) -{ - int i; - int *ptr = (int *)malloc(n*sizeof(*ptr)); - val = a; - gas = n - 1; - nsolid = ncmp = candidate = 0; - for(i=0; i aq(N); - RLOG("Generating antiqsort"); - antiqsort(N, aq); - Vector h; - for(int i = 0; i < N; i++) - h.Add(AsString(aq[i])); - RLOG("Now sorting"); - TimeStop tm; - Sort(h); - double t = tm.Seconds(); - RLOG("antiqsort " << t << " s"); + for(int n = 2; n <= 10; n++) { + Vector h; + int r; + for(int i = 0; i < N; i++) { + if(i % n == 0) + r = Random(); + h.Add(AsString(r)); + } + TimeStop tm; + Sort(h); + double t = tm.Seconds(); + RLOG("A " << n << " " << t << " s"); + } + for(int n = 2; n <= 10; n++) { + Vector h; + int r = Random(); + int n0 = 0; + for(int i = 0; i < N; i++) { + if(i / n != n0) { + r = Random(); + n0 = i / n; + } + h.Add(AsString(r)); + } + TimeStop tm; + Sort(h); + double t = tm.Seconds(); + RLOG("B " << n << " " << t << " s"); + } }