Joost van der Sluis wrote: > Hi all, > > i'm curious what happens here. If I make a recursive funtion inlined, it > runs way faster? > > Ackerman-test results: > $ ppc386 -O3p3r -dRecursiveInline ackerman.pp && cpu/bin/timeit > /home/joost/src/ackerman 10 > Ack(3,10): 8189 > Execution took 395377 microseconds. > > $ ppc386 -O3p3r ackerman.pp && cpu/bin/timeit /home/joost/src/ackerman 10 > Ack(3,10): 8189 > Execution took 568076 microseconds. > > Am I the only one with this speed-gain, and where does it come from?
Recursive functions are expanded one level if I'am not wrong :) > > > > ------------------------------------------------------------------------ > > program ackermann; > uses SysUtils; > > function Ack(M, N : integer) : integer; {$ifdef > RecursiveInline}inline;{$endif} > begin > if M = 0 then Ack := N+1 > else if N = 0 then Ack := Ack(M-1, 1) > else Ack := Ack(M-1, Ack(M, N-1)) > End; > > var NUM, a : integer; > > begin > if ParamCount = 0 then > NUM := 1 > else > NUM := StrToInt(ParamStr(1)); > > if NUM < 1 then NUM := 1; > a := Ack(3, NUM); > WriteLn( 'Ack(3,' + IntToStr(NUM) + '): ' + IntToStr(a) ); > end. > > > ------------------------------------------------------------------------ > > _______________________________________________ > fpc-devel maillist - fpc-devel@lists.freepascal.org > http://lists.freepascal.org/mailman/listinfo/fpc-devel _______________________________________________ fpc-devel maillist - fpc-devel@lists.freepascal.org http://lists.freepascal.org/mailman/listinfo/fpc-devel