I implemented the same variable argument function "varargs_adder"
in both Perl 5 (addit.pl) and Parrot (f4.pasm). 
The variable arguments can be strings, integers or floats
(I wanted to excercise dynamic variable behavior).

I called the function 500000 times in a loop to benchmark it.
The results are not what I expected:

Perl 5.6.1:       2.79 seconds
Parrot (non jit)  5.04 seconds
Parrot (jit)     13.65 seconds

Also note that the jitted version produces the wrong result
(21001094.100000 versus 21001097.970000)

I also tried using invokecc/foldup for the varargs function
(not included) but the results were much slower still.

Parrot was built from latest CVS yesterday on Cygwin/Windows.


$ cat addit.pl
#!/usr/bin/perl
#
# addit.pl
#
use strict;
sub varargs_adder {
    my $sum = 0;
    for (my $a = $#_; $a >= 0; --$a) {
        $sum += $_[$a];
    }
    return $sum
}
my $result = 0;
for (my $x = 500000; $x >= 0; --$x) {
    $result = varargs_adder(1000, 7.100, 87, "3.87", "21000000");
}
print "$result\n";


$ time perl addit.pl
21001097.97

real    0m2.790s
user    0m2.796s
sys     0m0.015s


$ cat f4.pasm
#
# f4.pasm
#
_main:
        set I9, 500000
AGAIN:
        dec I9
        lt I9, 0, FIN
        new P5, .SArray
        set P5, 5
        push P5, 1000
        push P5, 7.100
        push P5, 87
        push P5, "3.87"
        push P5, "21000000"
        bsr _varargs_adder
        branch AGAIN
FIN:
        print N0
        print "\n"
        end
_varargs_adder:
        new P2, .PerlNum
        assign P2, 0
        set I1, P5
LOOP:
        dec I1
        lt I1, 0, DONE
        set P1, P5[I1]
        add P2, P2, P1
        branch LOOP
DONE:
        set N0, P2
        ret


$ time parrot f4.pasm
21001097.970000

real    0m5.040s
user    0m5.046s
sys     0m0.015s


$ time parrot -j f4.pasm
21001094.100000

real    0m13.652s
user    0m13.655s
sys     0m0.015s


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

Reply via email to