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

Re: [FWP] thoughts on while(defined(EXP warnings



On Tue, Mar 14, 2000 at 12:36:35AM -0500, Michael G Schwern wrote:
> I don't see any performance drop when reading in a fairly large file:
> 
> #!/usr/bin/perl -w
> 
> use Benchmark;
> 
> # Might be /usr/dict/words
> $FILE = "/usr/share/dict/words";
> 
> timethese(shift || -3, 
>           {
>            "defined" => sub {
>                open(FILE, $FILE) or die $!;
>                while(defined($line = <FILE>)) { 1 }
>            },
>            "no defined" => sub {
>                open(FILE, $FILE) or die $!;
>                while($line = <FILE>) { 1 }
>            },
>           }
>          );
> 
> $ perl -w src/bench/defined_vs_not -10
> Benchmark: running defined, no defined, each for at least 10 CPU seconds...
>    defined: 13 wallclock secs (12.86 usr +  0.32 sys = 13.18 CPU) @  5.84/s (n=77)
> no defined: 13 wallclock secs (12.86 usr +  0.22 sys = 13.08 CPU) @  5.89/s (n=77)
> 
> (Similar results under 5.6 as under 5.005_03, similar results with a
> small file)

In perl5.005_03 and later, the two constructs are equivalent.  The magic of
while(<HANDLE>) is extended to while($line=<HANDLE>).

(Note the absence of any warnings from your benchmark script.)

Ronald

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe