Answer by FranG for Fastest sort of fixed length 6 int array
//Bruteforce compute unrolled count dumbsort(min to 0-index)void bcudc_sort6(int* a){ int t[6] = {0}; int r1,r2; r1=0; r1 += (a[0] > a[1]); r1 += (a[0] > a[2]); r1 += (a[0] > a[3]); r1 +=...
View ArticleAnswer by wildplasser for Fastest sort of fixed length 6 int array
Maybe I am late to the party, but at least my contribution is a new approach.The code really should be inlinedeven if inlined, there are too many branchesthe analysing part is basically O(N(N-1)) which...
View ArticleAnswer by PrincePolka for Fastest sort of fixed length 6 int array
I know this is an old question. But I just wrote a different kind of solution I want to share.Using nothing but nested MIN MAX, It's not fast as it uses 114 of each,could reduce it to 75 pretty simply...
View ArticleAnswer by Matthew K. for Fastest sort of fixed length 6 int array
I found that at least on my system, the functions sort6_iterator() and sort6_iterator_local() defined below both ran at least as fast, and frequently noticeably faster, than the above current record...
View ArticleAnswer by peter for Fastest sort of fixed length 6 int array
Sort 4 items with usage cmp==0. Numbers of cmp is ~4.34 (FF native have ~4.52), but take 3x time than merging lists. But better less cmp operations, if you have big numbers or big text.Edit: repaired...
View ArticleAnswer by peter for Fastest sort of fixed length 6 int array
Try 'merging sorted list' sort. :) Use two array. Fastest for small and big array.If you concating, you only check where insert. Other bigger values you not need compare (cmp = a-b>0).For 4 numbers,...
View ArticleAnswer by eyepatch for Fastest sort of fixed length 6 int array
I know I'm super-late, but I was interested in experimenting with some different solutions. First, I cleaned up that paste, made it compile, and put it into a repository. I kept some undesirable...
View ArticleAnswer by Morwenn for Fastest sort of fixed length 6 int array
This question is becoming quite old, but I actually had to solve the same problem these days: fast agorithms to sort small arrays. I thought it would be a good idea to share my knowledge. While I first...
View ArticleAnswer by Joe Crivello for Fastest sort of fixed length 6 int array
I stumbled onto this question from Google a few days ago because I also had a need to quickly sort a fixed length array of 6 integers. In my case however, my integers are only 8 bits (instead of 32)...
View ArticleAnswer by Olof Forshell for Fastest sort of fixed length 6 int array
Here is my contribution to this thread: an optimized 1, 4 gap shellsort for a 6-member int vector (valp) containing unique values.void shellsort (int *valp){ int c,a,*cp,*ip=valp,*ep=valp+5; c=*valp;...
View ArticleAnswer by Olof Forshell for Fastest sort of fixed length 6 int array
I believe there are two parts to your question.The first is to determine the optimal algorithm. This is done - at least in this case - by looping through every possible ordering (there aren't that...
View ArticleAnswer by Nico for Fastest sort of fixed length 6 int array
Looking forward to trying my hand at this and learning from these examples, but first some timings from my 1.5 GHz PPC Powerbook G4 w/ 1 GB DDR RAM. (I borrowed a similar rdtsc-like timer for PPC from...
View ArticleAnswer by Paolo Bonzini for Fastest sort of fixed length 6 int array
Never optimize min/max without benchmarking and looking at actual compiler generated assembly. If I let GCC optimize min with conditional move instructions I get a 33% speedup:#define SWAP(x,y) { int...
View ArticleAnswer by Steinar H. Gunderson for Fastest sort of fixed length 6 int array
The test code is pretty bad; it overflows the initial array (don't people here read compiler warnings?), the printf is printing out the wrong elements, it uses .byte for rdtsc for no good reason,...
View ArticleAnswer by Kevin Stock for Fastest sort of fixed length 6 int array
Looks like I got to the party a year late, but here we go...Looking at the assembly generated by gcc 4.5.2 I observed that loads and stores are being done for every swap, which really isn't needed. It...
View ArticleAnswer by GClaramunt for Fastest sort of fixed length 6 int array
Well, if it's only 6 elements and you can leverage parallelism, want to minimize conditional branching, etc. Why you don't generate all the combinations and test for order? I would venture that in some...
View ArticleAnswer by gcp for Fastest sort of fixed length 6 int array
If insertion sort is reasonably competitive here, I would recommend trying a shellsort. I'm afraid 6 elements is probably just too little for it to be among the best, but it might be worth a try....
View ArticleAnswer by phkahler for Fastest sort of fixed length 6 int array
While I really like the swap macro provided:#define min(x, y) (y ^ ((x ^ y) & -(x < y)))#define max(x, y) (x ^ ((x ^ y) & -(x < y)))#define SWAP(x,y) { int tmp = min(d[x], d[y]); d[y] =...
View ArticleAnswer by jheriko for Fastest sort of fixed length 6 int array
I ported the test suite to a PPC architecture machine I can not identify (didn't have to touch code, just increase the iterations of the test, use 8 test cases to avoid polluting results with mods and...
View ArticleAnswer by naj for Fastest sort of fixed length 6 int array
An XOR swap may be useful in your swapping functions.void xorSwap (int *x, int *y) { if (*x != *y) { *x ^= *y; *y ^= *x; *x ^= *y; } }The if may cause too much divergence in your code, but if you have...
View ArticleAnswer by Rex Kerr for Fastest sort of fixed length 6 int array
Since these are integers and compares are fast, why not compute the rank order of each directly:inline void sort6(int *d) { int e[6]; memcpy(e,d,6*sizeof(int)); int o0 =...
View ArticleAnswer by Daniel Stutzbach for Fastest sort of fixed length 6 int array
For any optimization, it's always best to test, test, test. I would try at least sorting networks and insertion sort. If I were betting, I'd put my money on insertion sort based on past experience.Do...
View ArticleAnswer by Paul R for Fastest sort of fixed length 6 int array
Here's an implementation using sorting networks:inline void Sort2(int *p0, int *p1){ const int temp = min(*p0, *p1); *p1 = max(*p0, *p1); *p0 = temp;}inline void Sort3(int *p0, int *p1, int *p2){...
View ArticleFastest sort of fixed length 6 int array
Answering to another Stack Overflow question (this one) I stumbled upon an interesting sub-problem. What is the fastest way to sort an array of 6 integers?As the question is very low level:we can't...
View ArticleAnswer by Don Hatch for Fastest sort of fixed length 6 int array
I thought I'd try an unrolled Ford-Johnson merge-insertion sort, which achieves the minimum possible number of comparisons (ceil(log2(6!)) = 10) and no swaps.It doesn't compete, though (I got a...
View ArticleAnswer by Aki Suihkonen for Fastest sort of fixed length 6 int array
I know the party's over 12 years ago, but still.I've found the best way to sort a handful of items using the parallel iteration ofshifted = [0 sorted](1 : length(sorted));shifted = max(shifted,...
View Article
More Pages to Explore .....