Newsgroups: comp.lang.apl
Path: watmath!watserv2.uwaterloo.ca!torn!cs.utexas.edu!uwm.edu!caen!sol.ctr.columbia.edu!The-Star.honeywell.com!umn.edu!csus.edu!sfsuvax1.sfsu.edu!emclean
From: emclean@sfsuvax1.sfsu.edu (Emmett McLean)
Subject: Re: J (simple) questions
Message-ID: <1993Feb17.074642.16091@csus.edu>
Sender: news@csus.edu
Organization: San Francisco State University
References: <1993Feb15.201003.9953@Princeton.EDU> <1993Feb17.022206.6635@csus.edu>
Date: Wed, 17 Feb 1993 07:46:42 GMT
Lines: 57

  
   I see that RR's method for looping is faster than mine. Thanks RR.

   Also, for your reference, I've attached a version using execute.

   - - - -
   Comparing times ...
   l =. 0 0 $'' NB. Looping using RR's method but my simple function
   l=.l,  'n =. 1000'
   l=.l,  '$. =., n #,: loop_start -. loop_end '
   l=.l,  'loop_start)'
   l=.l,  'y. =. y. + 2'
   l=.l,  'loop_end)'
   s=. l : ''  "0
   
   b =. i. 0 0  NB. Looping verses EM's method
   b =. b, 'i =. 0'       
   b =. b, 'n =. 1000'  NB. Actually I defined n needlessly in my 
   b =. b, 'loop) '     NB. earlier post.
   b =. b, 'y. =. y. + 2'
   b =. b, 'i =. >: i'
   b =. b, '$. =. > (i = n) { loop ; end ' 
   b =. b, 'end) y.'
   r =. b : '' "0   

   (5) 6!:2 's 4' NB. RR's method averaged over 5 times
2.492
   (5) 6!:2 'r 4' NB. EM's method averaged over 5 times
6.27
   s 3   NB. s and b do the same thing
2003
   b 3
2003
  
   - - - - -
   Using execute 
   b =. i. 0 0  NB. Looping using execute
   b =. b, 'i =. 0'       
   b =. b, 'n =. 1000' 
   b =. b, 'loop) ".(i -: n)#''$.=. end'' '
   b =. b, 'y. =. y. + 2'
   b =. b, 'i =. >: i'
   b =. b, '$. =. loop'
   b =. b, 'end) y.'
   t =. b : '' "0   

    - - - - -
   Using tacit definition
   (5) 6!:2 't 4' NB. So execute is faster than EM's method
5.208

   6!:2 ' 2&+ ^: (1000) 3'
2003
   
   (5) 6!:2 '2&+^:1000 (3)' NB. Tacit definition in the spirit of J
0.33
   
