I sort 10+ millions uint64_twith RGB data from .RAW files and 79% of my C program time is spent on qsort. I am looking for a faster view for this particular data type.
Being RAW graphic data, the numbers are very random and ~ 80% unique. No partial sorting or run of sorted data is expected. 4 uint16_tinside uint64_tare equal to R, G, B and zero (possibly a small number <= ~ 20).
I have the simplest comparison function that I can come up with unsigned long long(you CANNOT just subtract them):
qsort(hpidx, num_pix, sizeof(uint64_t), comp_uint64);
...
int comp_uint64(const void *a, const void *b) {
if(*((uint64_t *)a) > *((uint64_t *)b)) return(+1);
if(*((uint64_t *)a) < *((uint64_t *)b)) return(-1);
return(0);
}
StackExchange came up with a very interesting "Puzzle Programming and Code Golf", but they used floats. Then there are QSort, RecQuick, heap, stooge, tree, radix ...
Swenson / sort looked interesting, but did not have (obviously) Support for my type of data uint64_t. And the time of "quick sort" was the best. Some sources say the system qsortcan be anything, not necessarily βQuick Sortβ.
The C ++ variety bypasses the general void pointer listing and implements major performance improvements over C. There must be an optimized method for hacking U8 through a 64-bit processor with a strain rate.
System / Compiler Information:
I am currently using GCC with Strawberry Perl
gcc version 4.9.2 (x86_64-posix-sjlj, built by strawberryperl.com
Intel 2700K Sandy Bridge CPU, 32GB DDR3
windows 7/64 pro
gcc -D__USE_MINGW_ANSI_STDIO -O4 -ffast-math -m64 -Ofast -march=corei7-avx -mtune=corei7 -Ic:/bin/xxHash-master -Lc:/bin/xxHash-master c:/bin/stddev.c -o c:/bin/stddev.g6.exe
The first attempt to improve qsort, QSORT()!
inline qsort.
"READY-TO-USE"? qsort.h
-----------------------------
* Several ready-to-use examples:
*
* Sorting array of integers:
* void int_qsort(int *arr, unsigned n) {
* #define int_lt(a,b) ((*a)<(*b))
* QSORT(int, arr, n, int_lt);
--------------------------------
Change from type "int" to "uint64_t"
compile error on TYPE???
c:/bin/bpbfct.c:586:8: error: expected expression before 'uint64_t'
QSORT(uint64_t, hpidx, num_pix, islt);
, , , " "
#define QSORT_TYPE uint64_t
#define islt(a,b) ((*a)<(*b))
uint64_t *QSORT_BASE;
int QSORT_NELT;
hpidx=(uint64_t *) calloc(num_pix+2, sizeof(uint64_t));
QSORT_BASE = hpidx;
QSORT_NELT = num_pix;
QSORT(uint64_t, hpidx, num_pix, islt);
" " int, char * struct elt. uint64_t ? long long
QSORT(long long, hpidx, num_pix, islt);
c:/bin/bpbfct.c:586:8: error: expected expression before 'long'
QSORT(long long, hpidx, num_pix, islt);
: RADIXSORT:
: RADIX_SORT !
I:\br3\pf.249465>grep "Event" bb12.log | grep -i Sort
<< 1.40 sec average
4) Time=1.411 sec = 49.61%, Event RADIX_SORT , hits=1
4) Time=1.396 sec = 49.13%, Event RADIX_SORT , hits=1
4) Time=1.392 sec = 49.15%, Event RADIX_SORT , hits=1
16) Time=1.414 sec = 49.12%, Event RADIX_SORT , hits=1
I:\br3\pf.249465>grep "Event" bb11.log | grep -i Sort
<< 5.525 sec average = 3.95 time slower
4) Time=5.538 sec = 86.34%, Event QSort , hits=1
4) Time=5.519 sec = 79.41%, Event QSort , hits=1
4) Time=5.519 sec = 79.02%, Event QSort , hits=1
4) Time=5.563 sec = 79.49%, Event QSort , hits=1
4) Time=5.684 sec = 79.83%, Event QSort , hits=1
4) Time=5.509 sec = 79.30%, Event QSort , hits=1
3,94 , qsort !
, , , 80% , - , , , , 20%.
! !