[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Slow Script



On Tue, Feb 03, 2009 at 06:14:48PM +0100, Gorka wrote:
> Hi! I've got a perl script with this for:
> 
>   for (my $j=0;$j<=$#fichero1;$j++)
>   {
>     if (@fichero1[$j] eq $valor1)
>     
     if ($fichero1[$j] eq $valor1)
         ^^^

This is a beginner's mistake. You should
use warnings,  i.e. run perl with the -w flag,
or put 'use warnings;' at the top of your script.
That will catch this mistake, and probably many 
others that you will make, too.


>     {
>       $token = 1;
>     }
>   }

Seems like you will be better off improving your algorithm
rather than trying to get this code to run faster.

For the several million tests part you might use
a hash (dictionary) approach for dispatch rather than separate
tests as already suggested. That way you can handle 
your test-and-act with one calculation instead of millions
of comparisons.

If you have this large a problem, it may be worth posting
a fuller description of the larger problem you want to
solve at perlmonks.org or another programming-oriented forum. 

> The problem is that fichero1 has 32 millions of records and moreover I've
> got to repeat this for several millions times, so this way it would take
> years to finish.
> Does anybody know a way to optimize this script? Is there any other linux
> programing language I could make this more quickly whith?
> Thank you!
 
-- 
Joel Roth


Reply to: