Thanks a lot Bill that took it from 71 to 23 seconds, the match is an
exact match ie looks for the number in the first list selected by the
loop in the second list; is there yet further way to improve this by say
using some primitives somehow rather that looping through? 

-----Original Message-----
From: bill lam [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, 3 April 2007 12:55 PM
To: Programming forum
Subject: Re: [Jprogramming] Replace slow loop

Not sure what your match is, but a potential inefficiency is appending
boxed 
array repeatedly being quadratic, better replacing it by appending
integers that 
can be done in-place. eg.
   xs =: xs, _1, x

and obtain the final boxed array by
   <;._1 xs

Saunders, John (TQEH) wrote:
> Hi guys I'm using the below loop to match 2 lists of numbers it
> generates a boxed list of the index of matches,(the nth item in the
> boxed list xs contains the index of the matches in x of the nth item
of
> y) there can be multiple matches or none; the lists contain around
> 30,000 items and this will increase so it's slow and I'm sure its not
a
> good way to do it could anyone please suggest improved methods. 
> 
> match =: 3 : 0
> for. y    
> do.
> index =: index + 1
> if. index = #y do. break. end.
> x =: (I. ( dex { y) E. ,x)     
> xs =: xs,(<x)                                         
> end.
> )
> 
> thankyou
> John Saunders
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
> 


-- 
regards,
bill

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to