The fastest type of funtion?

Started by
6 comments, last by Arch@on 20 years, 8 months ago
What is the fastest function in C? Static void? What about the fastest member function in C++? Inline static void?
Advertisement
the fastest functions would be: inline and fastcall
the return type doesn''t matter since it is stored in EAX anyways.
slow functions include everything using a virtual function table i.e. late bindings: virtual and void*

don''t worry so much about function overhead, chances are that they wont matter a great deal in your projects. But the purpose of the different functions should be clear to you, because that will make a difference. If you''re ever in doubt use standard functions, use inline and fastcall only when appropriate.

MindRazor
How is fastcall different from inline?
Fastcall is an order in which to put argument on the stack.

Inline is the substitution of the calling with the actual body function.

ZixThree
a normal function put arguments in stack, fastcall force to put arguments in register when is possible
Okay, I can see where it is going now. Is support for fastcall processor or OS based? I''ve heard that fastcall doesn''t work with apples.

How big speed gains do you expect when you start to do fastcall?

Right now function overhead isn''t a problem for me, and to a project this scale it probably never will be. However there are some recursive functions in my code that are really pissing me off, since I was just wondering if there is any possibility to reduce the overhead in recursive functions?

Is a for loop faster than a recursive function of same length?
quote:Original post by Captain Goatse
Right now function overhead isn''t a problem for me, and to a project this scale it probably never will be. However there are some recursive functions in my code that are really pissing me off, since I was just wondering if there is any possibility to reduce the overhead in recursive functions?

Is a for loop faster than a recursive function of same length?


Iterative is usually prefered over recursive since you''ll use up less stack space while performing the operations, other than that i''m not sure on the speed differences.

It may not apply, but if possible make your function arguments const so that you don''t get the overhead of having the objects copied each time.

quote:Original post by Captain Goatse
Is a for loop faster than a recursive function of same length?


In general, I believe the answer is yes, a for loop is faster. However, some compilers will optimize away a tail-call recursion into a for loop.

This topic is closed to new replies.

Advertisement