Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
#!/usr/bin/perl
use strict;
use warnings;
use Carp;
use List::Util qw/first/;
use Benchmark;
sub benchmark {
my $subs = shift;
my ($k, $sub) = each %$subs;
my $value = $sub->();
croak "bad" if first { $value ne $_->() and print "$value\n", $_->(), "\n" } values %$subs;
Benchmark::cmpthese -1, $subs;
}
benchmark {
cat => sub {
return qx/cat $0/;
},
perl => sub {
open my $fh, "<", $0 or die "$!";
local $/ = undef;
return scalar <$fh>;
},
};
benchmark {
ls => sub {
return join "", map { chomp; $_ } qx/ls/;
},
perl => sub {
return join "", sort glob "*";
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.