all tasks
This commit is contained in:
parent
b83f433714
commit
68f8f3e56b
14735 changed files with 178959 additions and 0 deletions
18
Task/Time-a-function/Perl/time-a-function-1.pl
Normal file
18
Task/Time-a-function/Perl/time-a-function-1.pl
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
use Benchmark;
|
||||
use Memoize;
|
||||
|
||||
sub fac1 {
|
||||
my $n = shift;
|
||||
return $n == 0 ? 1 : $n * fac1($n - 1);
|
||||
}
|
||||
sub fac2 {
|
||||
my $n = shift;
|
||||
return $n == 0 ? 1 : $n * fac2($n - 1);
|
||||
}
|
||||
memoize('fac2');
|
||||
|
||||
my $result = timethese(100000, {
|
||||
'fac1' => sub { fac1(50) },
|
||||
'fac2' => sub { fac2(50) },
|
||||
});
|
||||
Benchmark::cmpthese($result);
|
||||
Loading…
Add table
Add a link
Reference in a new issue