> Actually Regex is taking more time instead of agrep. That's 
> why the idea
> of using either agrep or find.
> This is small input.txt which I am using it as a input file.
> If there is any other way of increasing the speed of same Perl script,
> it is really required.
> 

I don't have agrep but since you mentioned system(find) I figured I'd put
them to the test (using the input.txt file you sent) and, as suspected,
regex is faster. It would be even faster if you could use a more specific
(anchored) regex. I got these results from the below code. I'm guessing this
is because 'find' writes to STDOUT.

            Rate systemFind      regex
systemFind 128/s         --       -41%
regex      216/s        68%         --


### CODE

use strict;
use Benchmark qw(:all);

my $file = 'input.txt';
my $findthis = 'WalMart SSN 11';


cmpthese(1000, {
    'systemFind' => \&systemFind,
    'regex' => \&regex,
});


sub systemFind
{
        my $result = system("find \"$findthis\" $file");
        return $result;
}

sub regex
{
        open(FILE,"$file") || die "Can't open $file for reading :$!\n";
        foreach my $line(<FILE>)
        {
                return $line if ($line =~ /$findthis/);
        }
        close(FILE);
        return 0;
}
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to