x=. a.{~ 1e7 ?@$ 256
   timex'/:~x'
1.09009
   y=. 1e7 ?@$ 256
   '/:~x' %&timex '/:~y'
30.7846

Alternatives, unreasonably faster:

   '/:~x' %&timex 'x{~/:x'
12.1395
   '/:~x' %&timex '/:~&.(3&u:)x'
14.7522

(This also affects sorting of booleans and 2-byte characters; 4-byte characters were unaffected.)

The bug is caused by a misplaced closing brace; I have attached a patch mending it.

I happened across this while reading this thread: 
http://www.jsoftware.com/pipermail/programming/2014-March/035754.html
Now those results can be reproduced again!

(Interestingly, the difference in performance at first seemed to be smaller today than it was then; 5x vs 2-3x. But it jumps back up to an 8-11x delta when I increase the size of the array being sorted, so is probably a function of cache size.)

 -E
diff --git a/jsrc/vgsort.c b/jsrc/vgsort.c
index c151e72d..15d3e8d5 100644
--- a/jsrc/vgsort.c
+++ b/jsrc/vgsort.c
@@ -417,12 +417,12 @@ F2(jtgr2){F2PREFIP;PROLOG(0076);A z=0;I 
acr,api,d,f,m,n,*s,t,wcr;
    if(t&(C4T+INT+FL)){
     // If this datatype supports smallrange or radix sorting, go try that
     if(1==api)RZ(z=(t&INT?jtsorti:t&FL?jtsortd:jtsortu)(jtinplace,m,n,w))   // 
Lists of INT/FL/C4T
-   else if(d==2){
+   }else if(d==2){
     // 2-byte types, which must be B01/LIT/C2T.  Use special code, unless 
strings too short
     if(t&B01)             RZ(z=sortb2(m,n,w))  // Booleans with cell-items 2 
bytes long
     if(t&LIT+C2T&&n>4600)RZ(z=sortc2(m,n,w))  // long character strings with 
cell-items 2 bytes long   TUNE
    }else 
if(d<2)RZ(z=(t&B01&&(m==1||0==(n&(SZI-1)))?jtsortb:jtsortc)(jtinplace,m,n,w))  
// Lists of B01/LIT
-   }else if(d==4&&t&B01) RZ(z=sortb4(m,n,w))  // Booleans with cell-items 4 
bytes long
+   else if(d==4&&t&B01) RZ(z=sortb4(m,n,w))  // Booleans with cell-items 4 
bytes long
   }
    // for direct types, we have the choice of direct/indirect.  For indirect, 
we do grade followed by from to apply the grading permutation.
    // for direct, we move the data around until we get the final sort.  Direct 
is better for short items, for which the copy is cheap;
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to