Front page | perl.fwp |
Postings from November 2001
Re: Feel good benchmarks
Thread Previous
|
Thread Next
From:
Ian Phillipps
Date:
November 20, 2001 06:22
Subject:
Re: Feel good benchmarks
Message ID:
20011120142236.A26716@homer.diplex.co.uk
On Tue, 20 Nov 2001 at 12:57:11 +0000, mallum wrote:
> on Tue, Nov 20, 2001 at 01:53:40PM +0200, Vladi Belperchinov-Shabanski wrote:
> > it was really interesting for me how performance changed
> > between perl versions and other languages (interpreters/
> > scripts/etc.) but C points just nothing (actually result
> > is quite obvious:))...
I get, for the original script
75025perl 1.55s user 0.00s system
But:
sub f {
$_[0]<=1 ? $_[0] : f($_[0]-1)+f($_[0]-2)
}
print f(25);
75025perl 1.07s user 0.00s system
Defining the local parameter is doing a lot of damage. Some can be saved
by using $_[0] rather than "shift":
sub f {
my $num = $_[0];
return $num if $num <= 1;
return f($num-1) + f($num-2);
}
print f(25);
75025perl 1.34s user 0.00s system
Of course:
sub f {
$f[$_[0]] or $f[$_[0]]=$_[0]<=1?$_[0]:f($_[0]-1)+f($_[0]-2)
}
print f(25);
75025perl 0.00s user 0.00s system
.... but that's not the point, is it?
Ian
Thread Previous
|
Thread Next