I'm just explaining that the performance hit between the version using a
global and the version using an explicit argument is due to the copy of the
large array.  You can see that the times are the same if you include the
time to reset the global back to its original value (in the global version);
this is equivalent to the copy that the explicit version has to do.

It's a minor point but the difference initially puzzled me.

On Thu, Sep 18, 2008 at 3:30 PM, Sherlock, Ric <[EMAIL PROTECTED]>wrote:

> ---Devon McCormick wrote:
> > As a rule, code that avoids globals is better than code that
> > uses globals.
>
> I agree and I wasn't suggesting that those verbs using globals be used in
> production. I was just looking for a method to compare the different
> algorithms (that replaced 0 in M with _ and reassigned the result to M), in
> a way that algorithms using in-place assignment would have a chance to
> shine.
>
> > However, when I changed one of these functions to use an
> > explicit argument,
> > I was surprised by the performance difference:
> >
> > amZ1y=: 3 : 0
> >    zeros=. 0=y
> >    inf=. ($y)$_
> >    zeros} y,: inf
> > )
> >
> > NB. versus the original
> >
> > amZ1=: 3 : 0
> >  zeros=. M = 0
> >  inf=. ($M) $ _
> >  M=: zeros} M ,: inf
> > )
> >
> >    M=: M2      NB. As in the preceding messages...
> >    ts 'amZ1 '''''
> > 0.077218335 4.4459898e8
> >    ts 'amZ1y M'
> > 0.27146536 4.1104422e8
>
> I don't think these compare apples with apples. The second one doesn't
> apply the result to M. To do that I think you need to do:
>     ts 'M=: amZ1y M'
>
> But then assignment in no longer "in place".
>
> > NB. Big difference - but it's because of "cheating":
> >    ts 'amZ1 '''' [ M=: M2'
> > 0.27324012 3.7749037e8
>
> I don't understand what you're getting at here?
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>



-- 
Devon McCormick, CFA
^me^ at acm.
org is my
preferred e-mail
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to