why a.pl is faster than b.pl
- From: pangj@xxxxxxxxxxxxx (Jeff Pang)
- Date: Wed, 28 Dec 2005 20:38:32 +0800 (GMT+08:00)
hi,lists,
I have two perl scripts as following:
a.pl:
----
#!/usr/bin/perl
use strict;
my @logs = glob "~/logs/rcptstat/da2005_12_28/da.127.0.0.1.*";
foreach my $log (@logs) {
open (HD,$log) or die "$!";
while(<HD>){
if (
($_ =~ /�¢²á/o) ||
($_ =~ /�÷��/o) ||
($_ =~ /�¥µ®¿ì��/) ||
($_ =~ /�¦�¸/o) ||
($_ =~ /�ø�¨/o) ||
($_ =~ /·¢»õ/o) ||
($_ =~ /±±¾©/o) ||
($_ =~ /Ã?Ã?Ã?Ã?/o) ||
($_ =~ /���¢/o) ||
($_ =~ /��/o) ||
($_ =~ /°��ò/o) ||
($_ =~ /��/o) ) {
print $_;
}
}
close HD;
}
b.pl
----
#!/usr/bin/perl
use strict;
my $ref = sub { $_[0] =~ /�¢²á/o || $_[0] =~ /�÷��/o || $_[0] =~ /�¥µ®¿ì��/o ||
$_[0] =~ /�¦�¸/o || $_[0] =~ /�ø�¨/o || $_[0] =~ /·¢»õ/o ||
$_[0] =~ /±±¾©/o || $_[0] =~ /����/o || $_[0] =~ /���¢/o ||
$_[0] =~ /�ã�½/o || $_[0] =~ /°��ò/o || $_[0] =~ /�â·�/o };
my @logs = glob "~/logs/rcptstat/da2005_12_28/da.127.0.0.1.*";
foreach my $log (@logs) {
open (HD,$log) or die "$!";
while(<HD>){
print if $ref->($_);
}
close HD;
}
I run the 'time' command to get the running speed:
time perl a.pl > /dev/null
real 0m0.190s
user 0m0.181s
sys 0m0.008s
time perl b.pl > /dev/null
real 0m0.286s
user 0m0.278s
sys 0m0.007s
Why the a.pl is faster than b.pl? I think ever the resulte should be opposite.Thanks.
.
- Follow-Ups:
- Re: why a.pl is faster than b.pl
- From: Bob Showalter
- Re: why a.pl is faster than b.pl
- From: Chris Devers
- Re: why a.pl is faster than b.pl
- From: Paul Lalli
- Re: why a.pl is faster than b.pl
- Prev by Date: Re: problem using -f file operator
- Next by Date: Re: why a.pl is faster than b.pl
- Previous by thread: Image::Magick Annotate
- Next by thread: Re: why a.pl is faster than b.pl
- Index(es):
Relevant Pages
|