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

Re: [FWP] beauty vs. brains



>  $file = do { local $/, <FILE> };

Whoa.  Why don't I just do

  { local $/, $file = <FILE> }

Sigh.  Attached is a benchmark.  'local' and 'read' inconsistently beat
one another.

#!/usr/bin/perl

use Benchmark 'timethese';

print "Size of /usr/dict/words: ", -s "/usr/dict/words", "\n";

timethese(30, {
  'local' => q{
    open FILE, "/usr/dict/words";
    { local $/, $f = <FILE> }
    close FILE;
  },
  'do+local' => q{
    open FILE, "/usr/dict/words";
    $f = do { local $/, <FILE> };
    close FILE;
  },
  'read' => q{
    open FILE, "/usr/dict/words";
    read(FILE,$f,-s FILE);
    close FILE;
  },
});

__END__

Size of /usr/dict/words: 2486813
Benchmark: timing 30 iterations of do+local, local, read...
  do+local:  9 wallclock secs ( 6.23 usr +  3.20 sys =  9.43 CPU)
     local:  6 wallclock secs ( 2.29 usr +  2.99 sys =  5.28 CPU)
      read:  5 wallclock secs ( 2.23 usr +  3.03 sys =  5.26 CPU)

-- 
MIDN 4/C PINYAN, NROTCURPI, US Naval Reserve             japhy@pobox.com
http://www.pobox.com/~japhy/                  http://pinyaj.stu.rpi.edu/
PerlMonth - An Online Perl Magazine            http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc.    http://www.perlarchive.com/


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