Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

40 lines (33 sloc) 0.535 kb
#!perl -w
use strict;
use Benchmark qw(:all);
sub add{ $_[0] + $_[1] }
use macro::filter add => \&add;
printf "macro/%s\n", macro->VERSION;
my $n = 1000;
cmpthese timethese -1 => {
macro => sub{
my $sum = 0;
for my $i (1 .. $n){
$sum = add($sum, $i);
}
},
sub => sub{
my $sum = 0;
for my $i (1 .. $n){
$sum = &add($sum, $i);
}
},
do => sub{
my $sum = 0;
for my $i (1 .. $n){
$sum = do{ $sum + $i };
}
},
eval => sub{
my $sum = 0;
for my $i (1 .. $n){
$sum = eval{ $sum + $i };
}
},
};
Jump to Line
Something went wrong with that request. Please try again.