1. Inline vs. Function

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... ?

new topic     » topic index » view message » categorize

2. Re: Inline vs. Function

Inlining code is faster CK.

Euman
euman at bellsouth.net

new topic     » goto parent     » topic index » view message » categorize

3. Re: Inline vs. Function

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 message » categorize

4. Re: Inline vs. Function

On 18 Mar 2002, at 20:16, euman at bellsouth.net wrote:

> 
> Inlining code is faster CK.

Depending on if the compiler or interpreter actually inlines it or treats it as
a
function containing machine code. Plus, you haveto account for your 16bit 
code, if you use 16bit, using cpu time to thunk 32-16-32 again.

Then comes call-proc-with-pointers.
then call-func-with-pointers.
then call proc-with-data.
then call-func-with-data.
then comes overlays.
At least, that's what i discovered in Pascal.

then comes mutexes? 
then comes RPC over a LAN.

Kat

new topic     » goto parent     » topic index » view message » categorize

5. Re: Inline vs. Function

This from the infamous Euphoria Performance Tips html

In-lining of Routine Calls

If you have a routine that is rather small and fast, but is called a huge number
of times, *you will save time* by doing the
operation in-line, rather than calling the routine. Your code may become less
readable, so it might be better to in-line only
at places that generate a lot of calls to the routine

"Robert said that this only make your code less readable not that using function
calls are faster cause they arent"

Who uses 16 bit code in Euphoria Kat? Who thunks Euphoria code? (no one I know
cause theres no need)
besides, this is Euphoria not Pascal

Euman
euman at bellsouth.net

----- Original Message -----
From: "Kat" <gertie at PELL.NET>
To: "EUforum" <EUforum at topica.com>
Sent: Monday, March 18, 2002 11:05 PM
Subject: Re: Inline vs. Function


>
> On 18 Mar 2002, at 20:16, euman at bellsouth.net wrote:
>
> >
> > Inlining code is faster CK.
>
> Depending on if the compiler or interpreter actually inlines it or treats it
> as a
> function containing machine code. Plus, you haveto account for your 16bit
> code, if you use 16bit, using cpu time to thunk 32-16-32 again.
>
> Then comes call-proc-with-pointers.
> then call-func-with-pointers.
> then call proc-with-data.
> then call-func-with-data.
> then comes overlays.
> At least, that's what i discovered in Pascal.
>
> then comes mutexes?
> then comes RPC over a LAN.
>
> Kat
>
>
>
>

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu