Using a recursive version of the fibonacci function (with
the integer 32 as an argument) to test function call overhead 
I get these timings for various languages and configurations:

perl 5.6.1    fib.pl       10.93 seconds
python 2.2.2  fib.py        6.76 seconds
parrot        f.pasm        2.74 seconds
parrot -j     f.pasm        1.53 seconds
parrot        fib.imc (*)  22.07 seconds
parrot -j     fib.imc (*)  18.04 seconds

Prototyped functions in Parrot have a huge runtime overhead
as compared to normal subroutines. Is this to be expected?

fib.imc is basically like parrot/examples/benchmarks/fib.imc
except for 32 instead or 24 and s/var/pmc/g
The changes were made because fib.imc in CVS did not compile.

CVS parrot from yesterday running on Cygwin.
Full source code and timings below.


$ cat fib.pl
#!/usr/bin/perl -w
use strict;
sub fib {
        my $n = shift;
        return 1 if ($n < 2);
        return fib($n-1) + fib($n-2);
}
my $N = 32;
print fib($N), "\n";

$ time perl fib.pl
3524578

real    0m10.934s
user    0m10.936s
sys     0m0.015s


$ cat fib.py
import sys

def fib(n):
    if (n < 2):
        return 1
    return fib(n-2) + fib(n-1)

def main():
    N = 32;
    print fib(N)

main()

$ time python fib.py
3524578

real    0m6.765s
user    0m6.749s
sys     0m0.046s


$ cat f.pasm
_main:
        set I1, 32
        bsr _fibo
        print I0
        print "\n"
        end
_fibo:
        ge I1, 2, FIB2 
        set I0, 1
        ret
FIB2:
        save I1
        dec I1
        bsr _fibo
        dec I1
        save I0
        bsr _fibo
        restore I3
        add I0, I0, I3
        restore I1
        ret


$ time ../../parrot f.pasm 
3524578

real    0m2.743s
user    0m2.749s
sys     0m0.015s


$ time ../../parrot -j f.pasm 
3524578

real    0m1.530s
user    0m1.546s
sys     0m0.000s


$ cat fib.imc                 
.pcc_sub _main prototyped
    .param pmc argv
    .sym int argc
    argc = argv
    .sym int N
    N = 32
    if argc <= 1 goto noarg
    $S0 = argv[1]
    N = $S0
noarg:
    .sym float start
    .sym pmc fib
    fib = newsub _fib
    time start
    .pcc_begin prototyped
    .arg N
    .pcc_call fib
    .sym int r
    .result r
    .pcc_end
    .sym float fin
    time fin
    print "fib("
    print N
    print ") = "
    print r
    print " "
    sub fin, start
    print fin
    print "s\n"
    end
.end

.pcc_sub _fib prototyped
    .param int n
    if n >= 2 goto rec
    n = 1
    .pcc_begin_return
    .return n
    .pcc_end_return
rec:
    .sym int n1
    .sym int n2
    .sym int r1
    .sym int r2
    .sym pmc fib
    fib = P0
    n1 = n - 1
    n2 = n - 2
    .pcc_begin prototyped
    .arg n1
    .pcc_call fib
    .result r1
    .pcc_end
    .pcc_begin prototyped
    .arg n2
    .pcc_call fib
    .result r2
    .pcc_end
    n = r1 + r2
    .pcc_begin_return
    .return n
    .pcc_end_return
.end


$ time ../../parrot fib.imc
fib(32) = 3524578 22.044000s

real    0m22.078s
user    0m22.077s
sys     0m0.030s


$ time ../../parrot -j fib.imc
fib(32) = 3524578 18.017000s

real    0m18.048s
user    0m17.796s
sys     0m0.030s


__________________________________
Do you Yahoo!?
New Yahoo! Photos - easier uploading and sharing.
http://photos.yahoo.com/

Reply via email to