Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2005-06

Inlining recursive functions works - and it's fast too?

2 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Joost van der Sluis

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?

Met vriendelijke groeten, Joost van der Sluis CNOC Informatiesystemen en Netwerken http://www.cnoc.nl

Reply by email

Florian Klaempfl
to Joost van der Sluis
Joost van der Sluis wrote 15 lines
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 :)

Show quoted text 34 lines
------------------------------------------------------------------------ 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 - http://lists.freepascal.org/mailman/listinfo/fpc-devel

Reply by email