By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,728 Members | 1,165 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,728 IT Pros & Developers. It's quick & easy.

Fastest and optimise way to call a function

P: 15
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
Share this Question
Share on Google+
4 Replies


weaknessforcats
Expert Mod 5K+
P: 9,197
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

P: 15
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
Expert Mod 5K+
P: 9,197
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

P: 15
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.