Re: Fastest Way to...
- Posted by Pete Lomax <petelomax at blueyonder.co.uk> Oct 28, 2003
- 387 views
On Mon, 27 Oct 2003 22:12:41 -0600, "C. K. Lester" <euphoric at cklester.com> wrote: >Derek Parnell wrote: >> pos = pos * (pos <= 0) + (pos > 0) > >Oh, sweet! I think my version coulda been that if I had stayed with it. :) Maybe you had better play with this: constant ipos={3,-1,0} sequence pos sequence mask integer j atom t t=time() for i=1 to 1000000 do pos=ipos --============================ if pos[1] > 0 then -- 2.23 pos[1] = 1 end if if pos[2] > 0 then pos[2] = 1 end if if pos[3] > 0 then pos[3] = 1 end if --============================ -- mask=pos>0 -- 7.99 -- pos-=(pos*mask) -- pos+=mask --============================ -- mask=pos>0 -- 7.86 -- pos*=(mask=0) -- pos+=mask --============================ -- pos=pos*(pos<=0)+(pos>0) -- 7.83 --============================ -- while 1 do -- 5.86 -- j=find(1,pos>1) -- if not j then exit end if -- pos[j]=1 -- end while --============================ -- for k=1 to length(pos) do -- 2.68 -- if pos[k]>0 then pos[k]=1 end if -- end for end for t=time()-t ?t ?pos Those are my timings on the right for six different ways of doing this. You may need another zero or two on the for loop Pete