Timing is more reliable because it would catch cases where there is special code. e.g.
3 : '6!:2 ''+/\t'' [ t=. y...@$ 0' " 0 ]1e5 * 1 2 4 8 16 0.00162339 0.00377897 0.00746268 0.00730987 0.0142772 plus=: + 3 : '6!:2 ''plus/\t'' [ t=. y...@$ 0' " 0 ]100 * 1 2 4 8 16 0.00268498 0.0101298 0.0408069 0.258938 0.664755 I used 100 instead of 1e5 in the second case because 1e5 would have taken a loooooooong time. ----- Original Message ----- From: Oleg Kobchenko <[email protected]> Date: Friday, February 26, 2010 11:21 Subject: Re: [Jgeneral] Special code for suffix scan To: General forum <[email protected]> > > From: Roger Hui <[email protected]> > > > > > It is not in the Special Code section because there is > > nothing special about its implementation. > > There are examples of code that are even neater but are > > not "special" and so are not in Appendix B. For example, > A. . > > http://www.jsoftware.com/jwiki/Essays/Permutation_Index > > > > From: Zsbán Ambrus > > > > > On Fri, Feb 19, 2010 at 4:37 PM, Roger Hui wrote: > > > > The timings wouldn't be as follows if u/\. were quadratic: > > > > ----- Original Message ----- > > > >> Is there any chance that a future J version would > optimize > > > the monad > > > >> u/\. for any verb u to make only linear number of calls > to u > > > instead>> of quadratic? > > > > > > Wow, it's like that indeed, in the version I've got > too. Sorry. > > > > > > However, I don't see this documented in the Special Code > listing of > > > the Dictionary. Could you point me to where this is > > > documented, or > > > document this? > > Here's a simple mechanism to show how things work: > argument tracing. > > plus=: 4 : 'x + y [ smoutput > x,y' NB. define a tracer > > plus /\. 1 10 100 1000 > 10000 NB. > use illustrative data > 1000 > 10000 NB. linear algorithm > 100 11000 > 10 11100 > 1 11110 > 11111 11110 11100 11000 10000 > > plus /\ 1 10 > 100 NB. "triangular" algorithm > 1 10 > 10 100 > 1 110 > 1 11 111 > > plus /\ 1 10 100 1000 > 1 > 10 (a) > 10 100 --+ > 1 110 <- > + (b) > 100 1000 --+ > 10 1100 <-+ --+ > 1 1110 <-+ (c) > 1 11 111 1111 > (a)(b) (c) > > plus /\ 1 10 100 1000 10000 > 1 > 10 (a) > 10 100 --+ > 1 110 <- > + (b) > 100 1000 --+ > 10 1100 <-+ --+ > 1 1110 <- > + (c) > 1000 10000 --+ > 100 11000 <-+ --+ > 10 11100 <-+ --+ > 1 > 11110 <-+ (d) > 1 11 111 1111 11111 > (a)(b) (c) (d) > > > A variation with arguments and result: > > plus=: 4 : '(] ([smoutput) x,y,]) x + y' > plus /\ 1 10 100 1000 > 1 10 11 > 10 100 110 > 1 110 111 > 100 1000 1100 > 10 1100 1110 > 1 1110 1111 > 1 11 111 1111 ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
