in reply to Re: Speed reading (files)
in thread Speed reading (files)

I too have read about File::Slurp and how it's supposed to be super fast. However, check this out:
using read function 0.684900999069214 0.681570053100586 0.680304050445557 0.675194025039673 0.684563159942627 0.686581134796143 File::Slurp 1.57559299468994 1.5706889629364 1.5739688873291 1.5618691444397 1.56290698051453 1.58691692352295
That's using the same test as above, replacing
open(FILE,"<$file") || die $!; my $data = do { local $/; <FILE> }; close(FILE);
with
my $data = read_file($file);

Replies are listed 'Best First'.
Re^3: Speed reading (files)
by xdg (Monsignor) on Aug 04, 2005 at 16:14 UTC

    Have you seen the article in the File::Slurp distribution? At it's core, it's doing something very similar to the "read" approach. I'd guess the speed difference you're seeing is due to the option/error/context checking that it's doing, which your hand-coded example is not.

    -xdg

    Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.