Using M. can indeed provide a significant performance boost, but
benchmarks on expressions using M. need to be done with care, 
since the second time such an expression is executed can be 
much faster than the first.  

fib=: 3 : 0 M.
 if. 1>:y do. y else. (fib y-1)+fib y-2 end.
)
   6!:2 'fib 32'
0.016037
   6!:2 'fib 32'
3.96698e_5
   6!:2 'fib 32'
3.88318e_5

In   ts 'V1 3000'   is the time done first or the space is done first? 
If   ts=:6!:2 , 7!:[EMAIL PROTECTED]  , then it depends on whether the left 
tine of 
a fork is done first or the right tine.

   (1!:2&[EMAIL PROTECTED]: , 1!:2&[EMAIL PROTECTED]:) 12
24
144
144 24

That is, the right tine is done first.  Therefore in   ts blah    
the space is done first, which "primed the pump" and made 
the time look better than it really is.



----- Original Message -----
From: "R.E. Boss" <[EMAIL PROTECTED]>
Date: Sunday, September 30, 2007 12:40
Subject: RE: [Jprogramming] stack overflow
To: 'Programming forum' <[email protected]>

> If your V is defined a bit different you can use (the new) M. 
> and get quite
> a performance improvement.
> 
> V1=: ((>@:{.(V_ltk;V_gtk)>@:{:)@:V1@:<:)`
> ((b$~+/S<:k);(b$~16,~+/S>k)"0)@.(0=]) M.      NB. J602; line wrap!
> 
>    ts'V1 3000'
> 0.0011774627 4692672
> 
> much faster than
> 
>    ts'(>@:{.(V_ltk;V_gtk)>@:{:)^:3000 
> ((b$~+/S<:k);(b$~16,~+/S>k)"0)0'0.37991681 57280
> 
>        (V1 3000)-
> :(>@:{.(V_ltk;V_gtk)>@:{:)^:3000((b$~+/S<:k);(b$~16,~+/S>k)"0)0               
> NB. line wrap!
> 1
> 
> The stack problem also disappeared!
> 
>    ts'V 3000'
> |stack error: V
> |       V 3000
> 
> It seems M. changes performance programming drastically.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to