develooper Front page | perl.fwp | Postings from November 2001

Re: Feel good benchmarks

Thread Previous | Thread Next
Michael G Schwern
November 20, 2001 11:27
Re: Feel good benchmarks
Message ID:
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

    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};

real    0m0.171s
user    0m0.090s
sys     0m0.050s

but that's not really a challenge.  Let's try... oh, the 500th
fibonacci number.

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) {
        printf("%.0f", f(500));

real    0m0.051s
user    0m0.000s
sys     0m0.020s

Of course, that mess probably proves my point pretty well.


Michael G. Schwern   <>
Perl Quality Assurance	    <>	       Kwalitee Is Job One
Let's leave my ass out of this, shall we?

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About