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.
leo
.sub optc @IMMEDIATE # TODO turn on -Oc # print "optc\n" .end .sub _main @MAIN .param pmc argv .local pmc count, product .local float start, end count = new PerlInt count = 1000 .local int argc argc = elements argv if argc < 2 goto def $S0 = argv[1] count = $S0 def: .local int i i = 0 start = time .local pmc n loop: n = clone count product = new PerlInt product = 1 product = _fact(product, n) inc i if i < 1000 goto loop end = time end -= start print product print "\n" print end print "\n" .end .sub _fact .param pmc product .param pmc count if count > 1 goto recurs .return (product) recurs: product *= count dec count product = _fact(product, count) .return (product) .end
.sub optc @IMMEDIATE # TODO turn on -Oc # print "optc\n" .end .sub _main @MAIN .param pmc argv .local pmc count, product .local float start, end count = new PerlInt count = 1000 .local int argc argc = elements argv if argc < 2 goto def $S0 = argv[1] count = $S0 def: .local int i i = 0 start = time .local pmc n loop: n = clone count product = new PerlInt product = 1 save n save product bsr fact restore product inc i if i < 1000 goto loop end = time end -= start print product print "\n" print end print "\n" goto ex fact: saveall .local pmc product, count restore product restore count if count > 1 goto recurs restoreall save product ret recurs: product *= count dec count save count save product bsr fact restore product restoreall save product ret ex: .end