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
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
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.
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 "
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
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;
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
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