At 10:03 PM +0100 11/17/04, Leopold Toetsch wrote:
Dan Sugalski wrote:

[ this came up WRT calling conventions ]

I assume he's doing bsr/ret to get into and out of the sub, which is going to be significantly faster.

Who says that?

As already stated, I don't consider these as either light-weight nor faster. Here is a benchmark.

Below are 2 version of a recursive factorial program. fact(100) is calculated 1000 times:

PIR           1.1 s
bsr/ret       2.4 s
PIR/tailcall  0.2s

Unoptimized Parrot, default i.e. slow run core.

Way to go with the overkill. I'm impressed. However, written more sanely the results are:


PIR:
real    0m4.149s
user    0m4.120s
sys     0m0.030s

bsr/ret:
real    0m1.266s
user    0m1.260s
sys     0m0.000s


Chopping out the multiplication (since that's a not-insignificant amount of the runtime for the bsr/ret version) gives:


PIR:
real    0m3.016s
user    0m2.990s
sys     0m0.030s

bsr/ret
real    0m0.344s
user    0m0.340s
sys     0m0.010s

The bsr/ret version is:
start:
    new P16, .PerlInt
    set P16, 1000

    elements I16, P5
    lt I16, 2, def
    set S0, P5[1]
    set P16, S0

def: set I16, 0
time N16
save N16


loop:
    clone P1, P16
    new P0, .PerlInt
    set P0, 1
    save P16
    save I16
    bsr fact
    restore I16
    restore P16
    inc I16
    lt I16, 1000, loop
    restore N16
    time N17
    sub N17, N17, N16
    print P0
    print "\n"
    print N17
    print "\n"
    end



# in: P0 is product, p1 is count
# out: P0 is new product
fact:
  gt P1, 1, doit
  ret
doit:
  mul P0, P0, P1
  dec P1
  bsr fact
  ret

--
                                Dan

--------------------------------------it's like this-------------------
Dan Sugalski                          even samurai
[EMAIL PROTECTED]                         have teddy bears and even
                                      teddy bears get drunk

Reply via email to