Front page | perl.fwp |
Postings from November 2001
Re: Feel good benchmarks
Thread Previous
|
Thread Next
From:
Michael G Schwern
Date:
November 20, 2001 11:27
Subject:
Re: Feel good benchmarks
Message ID:
20011120142512.X11883@blackrider
On Tue, Nov 20, 2001 at 01:53:40PM +0200, Vladi Belperchinov-Shabanski wrote:
> the C demo at the end is out of topic, isn't it?
>
> 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:))...
Check your dashboard, I think the "sense of humor needs service" light
is on. ;)
Oh, and just so we don't all get too into playing Golf to make code go
faster:
use Tie::Math;
tie %fibo, 'Tie::Math', sub { f(N) = f(N-1) + f(N-2) },
sub { f(0) = 0; f(1) = 1 };
print $fibo{25};
75025
real 0m0.171s
user 0m0.090s
sys 0m0.050s
but that's not really a challenge. Let's try... oh, the 500th
fibonacci number.
1.39423224561698e+104
real 0m0.461s
user 0m0.380s
sys 0m0.070s
The C program is still working on the 50th number.
Of course, if I wanted this to be a fair test (which I don't), I'd do:
#include <stdio.h>
double fibs[500];
void init_fibs (void) {
int idx;
for(idx = 0; idx <= 500; idx++) {
fibs[idx] = 0;
}
}
double f (int num) {
if( num <= 1 )
return num;
else if( !fibs[num] )
fibs[num] = f(num-1) + f(num-2);
return fibs[num];
}
int main (void) {
init_fibs();
printf("%.0f", f(500));
}
139423224561697698330489613862193018947914545343780323868775030943672596190605867771863846635039486902272
real 0m0.051s
user 0m0.000s
sys 0m0.020s
Of course, that mess probably proves my point pretty well.
--
Michael G. Schwern <schwern@pobox.com> http://www.pobox.com/~schwern/
Perl Quality Assurance <perl-qa@perl.org> Kwalitee Is Job One
Let's leave my ass out of this, shall we?
Thread Previous
|
Thread Next