Re: Very slow array searching

2003-07-29 Thread John W. Krahn
Paul Archer wrote: > > 3:20pm, Ramprasad wrote: > > > > Rafaqat Ali Chaudhry wrote: > > > > > > The array has at least 20K elements. This piece of code is taking up > > > almost 100% of the CUP cycles. Would somebody please suggest some > > > alternative solution. > > > > You can improve the code

Re: Very slow array searching

2003-07-29 Thread Paul Archer
In addition to the suggestions already given, you could sort your array, and then look at the middle and cut it in half (potentially several times). I forget the name for this technique, though... For example, you have 1000 elements, sorted. You compare your number to the 500th element. If it's hi

RE: Very slow array searching

2003-07-29 Thread Jeff 'japhy' Pinyan
On Jul 29, Bob Showalter said: >Bob Showalter wrote: >> ... >> A more efficient iterative approach using a numeric equality test >> would be: >> >>sub checkNumber { >> $_[0] == $_ && return 1 for @numbers; >> return; >>} >> >> This returns 1 for a match and undef for no match.

RE: Very slow array searching

2003-07-29 Thread Bob Showalter
Bob Showalter wrote: > ... > A more efficient iterative approach using a numeric equality test > would be: > >sub checkNumber { > $_[0] == $_ && return 1 for @numbers; > return; >} > > This returns 1 for a match and undef for no match. Heck, you can even leave off the last "

RE: Very slow array searching

2003-07-29 Thread Bob Showalter
Rafaqat Ali Chaudhry wrote: > Dear all, > > I've a function which searches a given number from an array and > returns the result. > > Function: > > 1.sub checkNumber($) > 2.{ > 3.my ($l_number) = @_; > 4.my $l_status; > 5.my @matches= grep { /$l_numbe

Re: Very slow array searching

2003-07-29 Thread Ramprasad
Rafaqat Ali Chaudhry wrote: Dear all, I've a function which searches a given number from an array and returns the result. Function: 1. sub checkNumber($) 2. { 3. my ($l_number) = @_; 4. my $l_status; 5. my @matches= grep { /$l_number/ } @numbers;

RE: Very slow array searching

2003-07-29 Thread Rafaqat Ali Chaudhary
Thanks George. It reduced the total time to almost 50%. Rafaqat Ali Chaudhary -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of George P. Sent: Tuesday, July 29, 2003 11:57 To: Rafaqat Ali Chaudhary Cc: [EMAIL PROTECTED] Subject: Re: Very slow array

Re: Very slow array searching

2003-07-28 Thread George P.
On Tue, 29 Jul 2003, Rafaqat Ali Chaudhary wrote: > Dear all, > > I've a function which searches a given number from an array and returns > the result. > > Function: > > 1.sub checkNumber($) > 2.{ > 3.my ($l_number) = @_; > 4.my $l_status; > 5.my @ma