Efficiency is directly related the size of data given to a primitive at one time. Larger is more efficient, because set-up costs are amortized over more elements.
For example: f0=: ]`(>:@])@.(3<])"0 f1=: + 3&< x=: 1e6 [EMAIL PROTECTED] 10 (f0 -: f1) x 1 ts=: 6!:2 , 7!:[EMAIL PROTECTED] ts 'f0 x' 0.388286 2.93612e7 ts 'f1 x' 0.0199689 9.43795e6 In f0, the agenda (and ] and >:@]) see x one atom at a time. In f1 + and 3&< see x in toto. g0=: ]`(>:@])@.[ g1=: + g2=: >:@]^:[ 0 1 (g0 -: g1)"0 _ x 1 1 0 1 (g0 -: g2)"0 _ x 1 1 ts"1 '01',"0 1 ' g0 x' 4.38256e_6 832 0.00609205 4.1952e6 ts"1 '01',"0 1 ' g1 x' 0.00584246 4.19514e6 0.00608435 4.19514e6 ts"1 '01',"0 1 ' g2 x' 0.00566479 4.19526e6 0.0061191 4.19533e6 There is little to choose between g0 g1 g2 because in all three the primitives see the right argument all at once. It is not always straightforward to determine how much data a primitive sees, because sometimes the implementation uses special code for a phrase. For example, rot=: |. a=: 1e5 [EMAIL PROTECTED] 2 b=: 1e5 2 [EMAIL PROTECTED] 100 a (rot"_1 -: |."_1) b 1 You may think that rot"_1 and |."_1 feed the same amount of data to the primitive. However, |. has integrated rank support, and: ts 'a rot"_1 b' 0.066072 1.05005e6 ts 'a |."_1 b' 0.00622701 1.57376e6 ----- Original Message ----- From: Tracy Harms <[EMAIL PROTECTED]> Date: Saturday, July 28, 2007 14:26 Subject: [Jprogramming] when and why to avoid agenda, and/or small selections To: [email protected] > John Randall, in summarizing advice for J programming, > wrote the following: > > > Avoid small selections: use #~f whenever possible. > > I almost never use @. . > > As I having been studying gerunds recently, agenda > (@.) was showcased in conjunction with them. My > questions today are: > > Is the advice regarding 'selection', above, not > applicable with regard to the use of agenda with > gerunds. > > If not, the claim suggests it is typically better to > find an alternative to agenda. What is the heart of > the disadvantage of agenda? Is it a matter of speed > of the resulting computation? > > How should the term 'selection' be understood in that > advice? > > Thank you, in advance, for all replies. ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
