I suggested qsort simply because it would require no coding to make it b/c it is already made. If you have the time to write a sort, use radix i guess.
This is a discussion on simple int sort within the C++ Programming forums, part of the General Programming Boards category; I suggested qsort simply because it would require no coding to make it b/c it is already made. If you ...
I suggested qsort simply because it would require no coding to make it b/c it is already made. If you have the time to write a sort, use radix i guess.
I actually think quicksort will be fine in this case. Z depth sorting is done once per frame so it's not necessarily the great bottleneck. If you were doing a sort once per polygon I'd have to insist on radix.
I'll probably eventually go with a radix sort (all of my values are positive, it's a 2d-hex tile game (simulated 3d)).
I've profiled my original generic little bubble sort on my laptop (read: my low-end, p2 233mhz 4MB vidram system) and there was no noticeble slowdown.
I say probably because this isn't an optimization that requires immediate attention, nor will it be much trouble to change it later (since it just involves changing one algorithm in a single function that will still take the same parameters and return the same result regardless of which sort I use).
Thanks again for all the suggestions.
Last edited by jdinger; 08-06-2002 at 04:01 PM.
Why not compare all the options? Here's a simple way to do it:
Overload the algorithms with - say - 100 to 10,000 times normal load. Before each sort begins:
start = clock();
RadixSort();
stop = clock();
radixTime = (stop - start) / 1000;
printf("Radix Sort Time Was %d Seconds.", radixTime);
...this would give you a good idea of which is superior...
Code:int main(void){srand(time(0));for(double l=rand(),l0=0,l00=0;;l0+=0.1){for(double l000=0;l000 <1;l000+=.001,l+=((double)rand()/RAND_MAX)/0x64,l00+=((sin(l*0x8*atan(l0)*l000-(l0*0x8*atan (l)))*0.5)+0.5)){l00-=floor(l00);for(size_t l0000=0,l00000=(size_t)(0x50*(l00));l0000<l00000;++l0000 )putchar(0x20);putchar(0x61+(int)((double)rand()/RAND_MAX*0x1a));putchar('\n');}}return 0;}