Re: Inline vs. Function

new topic     » goto parent     » topic index » view thread      » older message » newer message

C.K. Lester writes:
> Rob, I can't remember... Is inlining code much faster than calling it as 
> a function? I wouldn't think there'd be much speed loss in turning 
> chunks of code into a function... ?

On my machine, the code below shows that if incrementing
an integer variable by 1 costs 1 unit, then a call with no arguments to
a procedure costs about 14 units. I imagine that additional 
arguments would cost a few units each.

Whether you in-line or not, depends on how often you call
the routine, how small the routine is, how much work is performed
per call, how badly you want to speed things up, etc. 
There is no simple rule.
There are also second-order effects, like caching.
Having one copy of a piece of code in a routine may give
you better caching, than having 20 copies of that code
scattered around your program.

procedure foo()
end procedure

atom t
integer x

t = time()
for i = 1 to 100000000 do
    foo()
end for
? time()-t

x = 0
t = time()
for i = 1 to 100000000 do
    x = x + 1
end for
? time() -t

t = time()
for i = 1 to 100000000 do
    -- overhead of empty  loop - subtract this from the above times
end for
? time() -t

Regards,
   Rob Craig
   Rapid Deployment Software
   http://www.RapidEuphoria.com

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu