Hi,
I see that the sort_u8() func into schrofilter.c use a basic bubble sort scheme => is it volontary ? I have make a benchmark between this sort_u8() routine and the standard qsort() C func and found that the qsort() routine have betters performances whis big data arrays but lowers performances when it is used very frequently with very littles arrays to sort On another side, I have implemented a bubblesort2() func that is relatively similar to sort_u8() but that seem more performant than qsort() and sort_u8() when it is very frequently used with a data array on the range of 32 to 1024 bytes => what is the more usual /more frequently array data range that is used with the sort_u8() func ? If the data size to sort is lesser than 32, the sort_8() func is generally the fastest If the date size to sort is more than 1024, the qsort() func is generally the fastet And between this two extremes, my bubblesort2() routine seem generally outperform the last twos :) Here is the new function : static void sort_u8_ext(uint8_t * d, int n, int firsts) { int i, j, k; int x; int lower, upper, toswap; int swapped = 0; if ( (n < 2) || ( firsts < 1) ) return; if ( firsts >= n ) { firsts = n -1 ; } for (i = 0; i < firsts ; i++) { toswap = 0; lower = d[i]; for( j = i+1; j < n ; j++) { if (d[j] < lower ) { toswap = j; lower = d[j]; } } if ( toswap ) { x = d[i]; d[i] = d[toswap]; d[toswap] = x; } } for (i = n -1 ; i >= (n - firsts) ; i--) { toswap = 0; upper = d[i]; for( j = i-1 ; j >= firsts ; j--) { if (d[j] > upper ) { toswap = j; upper = d[j]; } } if ( toswap ) { x = d[i]; d[i] = d[toswap]; d[toswap] = x; } } } We can set the number of values that we only want to sort at the beginning and at the end, using the "firsts" variable (in this case, only the middle of the array isn't sorted, but maximums and minimums values are automatically sorted first by this func) Note that the variable "firsts" can too be automatically set to n/2 outside this func for to force this routine to reorder entirely the array to sort (and not only the firsts lessers and greaters values of the array) @+ Yannoo ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ Schrodinger-devel mailing list Schrodinger-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/schrodinger-devel