$ ls -sh bigfile.txt
2.8G bigfile.txt
$ cat direct_sysread.pl
use Fcntl qw(:DEFAULT);
use Symbol;
my $file = shift @ARGV;
my $fh = gensym;
sysopen $fh, $file, O_RDONLY;
my $content;
sysread $fh, $content, -s $file;
$ cat file_slurp.pl
use File::Slurp;
my $file = shift @ARGV;
open my $fh, "<", $file or die $!;
my $content = read_file ($file);
$ time direct_sysread.pl bigfile.txt
real 0m1.785s
user 0m0.008s
sys 0m1.776s
$ time file_slurp.pl bigfile.txt
real 0m4.994s
user 0m0.924s
sys 0m4.052s
|