My experiments show ~. faster than ~.!.0 for boxed character arrays of rank 2 (disagreeing with Roger's point 1)

   array =. (100000 2 ?@$ 200 10)  (<;.0~ ,.)~"1 _  a.
   50 {."1 ": array
+--++-------+-------+--++---+--------+--------+---
|YZ||�������|ABCDEFG| || |��������|��������|���
+--++-------+-------+--++---+--------+--------+---
   array2 =. ,.~ array
   $array2
100000 2
   10 ts '~. array'
0.0212086 1.57357e6
   10 ts '~.!.0 array'  NB. No change for rank 1
0.0211375 1.57389e6
   10 ts '~. array2'
0.0508845 2.09786e6
   10 ts '~.!.0 array2'  NB. Slowdown for rank 2
0.151277 2.22925e6

Henry Rich

On 8/19/2014 7:43 PM, Roger Hui wrote:
0. For a floating point vector, ~.!.0 is faster than ~., but not to the
extent that Bill Lam implied.

    timer=: 6!:2
    x=: 1e6 ?@$ 0

    10 timer '~.x'
0.136236
    10 timer '~.!.0 x'
0.0814054

Same comments apply to other functions in the index-of family.

1. For non-numeric arguments (and boxed arrays not involving numbers),
~.!.0 should run at the same speed as ~.

    x=: a.{~ 1e6 12 ?@$ 256
    10 timer '~.x'
0.13204
    10 timer '~.!.0 x'
0.130772

2. Floating point matrices can have O(n^2) performance.  It's best to use
~.!.0 if you can get away with it.

    3 : '10 timer ''~.t'' [ t=. 1.5,.y ?@$ 0'"0 ]10^0 1 2 3 4
3.03225e_6 5.45805e_6 0.000412806 0.012665 1.01016

    3 : '10 timer ''~.!.0 t'' [ t=. 1.5,.y ?@$ 0'"0 ]10^0 1 2 3 4
4.05855e_6 4.3851e_6 3.11155e_5 0.000177643 0.0015026

3. Boxed arrays involving numerics (even all integers) can have O(n^2)
performance.  It's best to use ~.!.0 if you can get away with it.

I don't remember the exact details of how this comes about.  Best to check
the source, or at least run a few (small) benchmarks.

3. The interpreter checks for interrupts predominantly during memory
allocation.  If there is a computation that runs for a long time and
appears to be uninteruptible, this is the most likely culprit.  Note: most
anything in J can not proceed without allocating memory.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to