468,510 Members | 1,349 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,510 developers. It's quick & easy.

Fastest and optimise way to call a function

If a routine has to be called 10,000 times then what will be the fastest and the optimised way of calling this routine as per my knowledge "for loop" is one way....inline function won't solve the problem.....will preprocessor "#typedef" will be a benifit?
Jan 30 '08 #1
4 1353
weaknessforcats
9,207 Expert Mod 8TB
The fastest way is the inline function. There are no calls. No stack frames to allocate and deallocate.

10000 copies of the function along the thread of execution is the fastest way.

But there's bloat. Next best is an inline function inside a loop.

Next best is a function call inside a loop.
Jan 30 '08 #2
Inline function wont increase the size of the program...as every time a inline function is called the whole function is copied at the the time of the call of the function.

As requirement is though the fastest method but it should be an optimised one.

The fastest way is the inline function. There are no calls. No stack frames to allocate and deallocate.

10000 copies of the function along the thread of execution is the fastest way.

But there's bloat. Next best is an inline function inside a loop.

Next best is a function call inside a loop.
Jan 30 '08 #3
weaknessforcats
9,207 Expert Mod 8TB
Inline function wont increase the size of the program...as every time a inline function is called the whole function is copied at the the time of the call of the function.
This is just not correct. Inline functions are copied inline by the compiler at compile time. That's why they are called in-line. At run time the bits are just executed. No calls.
Jan 31 '08 #4
Thank you very much for clearing the doubt:)
Jan 31 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

12 posts views Thread by windandwaves | last post: by
11 posts views Thread by Ignacio X. Domínguez | last post: by
14 posts views Thread by Mark Broadbent | last post: by
15 posts views Thread by Buddy Home | last post: by
6 posts views Thread by Klaas Vantournhout | last post: by
reply views Thread by NPC403 | last post: by
3 posts views Thread by gieforce | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.