Created
May 17, 2014 02:49
-
-
Save dagolden/973bcfa11816e2d96c65 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use v5.10; | |
use strict; | |
use warnings; | |
use Benchmark qw( cmpthese ); | |
use Path::Tiny; | |
use File::Slurp qw/read_file/; | |
sub fast_slurp { | |
my ($file) = @_; | |
open my $fh, "<:unix", $file or die $!; | |
my $size = -s $fh; | |
my $buf; | |
read $fh, $buf, $size; # File::Slurp in a nutshell | |
return $buf; | |
} | |
for my $f (qw/foo-small foo-med foo-big/) { | |
say "\nBENCHMARKING $f"; | |
my $path = path($f); | |
my $count = -1; | |
cmpthese( | |
$count, | |
{ | |
'Path::Tiny' => sub { my $raw = $path->slurp_raw }, | |
'File::Slurp' => sub { my $raw = read_file( $f, binmode => ':raw' ) }, | |
'fast slurp' => sub { my $raw = fast_slurp( $f ) }, | |
} | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment