-rw-r--r-- 1474 sortbench-20240116/bench-vxsort.cc raw
#include "vxsort_targets_enable_avx2.h" #include "vxsort.h" #include "vxsort.avx2.h" #include "machine_traits.avx2.h" #include "smallsort/bitonic_sort.avx2.h" long long ticks(void) { unsigned long long result; asm volatile(".byte 15;.byte 49;shlq $32,%%rdx;orq %%rdx,%%rax" : "=a"(result) :: "%rdx"); return result; } #define N 131072 #define TIMINGS 127 int32_t r[N] __attribute__((aligned(4096))); int32_t x[(TIMINGS+1)*N] __attribute__((aligned(4096))); int32_t y[N] __attribute__((aligned(4096))); long long t[TIMINGS+1] __attribute__((aligned(4096))); int main() { auto sorter = vxsort::vxsort<int, vxsort::vector_machine::AVX2, 8>(); for (long long n = 1;n <= N;n += 1+(n/16)) { for (long long i = 0;i < n;++i) r[i] = random(); for (long long j = 0;j <= TIMINGS;++j) for (long long i = 0;i < n;++i) x[j*n+i] = r[i]; for (long long j = 0;j <= TIMINGS;++j) t[j] = ticks(); for (long long j = 0;j <= TIMINGS;++j) { t[j] = ticks(); sorter.sort(x+j*n,x+j*n+n-1); } for (long long i = 0;i < n;++i) y[i] = r[i]; std::sort(y,y+n); for (long long j = 0;j <= TIMINGS;++j) for (long long i = 0;i < n;++i) assert(y[i] == x[j*n+i]); for (long long i = 0;i < TIMINGS;++i) t[i] = t[i+1]-t[i]; std::sort(t,t+TIMINGS); printf("%lld %lld %lld %lld\n",n,t[TIMINGS/4],t[TIMINGS/2],t[(3*TIMINGS)/4]); } return 0; } #include "vxsort_targets_disable.h"