Archived

This topic is now archived and is closed to further replies.

Arch@on

The fastest type of funtion?

Recommended Posts

Guest Anonymous Poster
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

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
a normal function put arguments in stack, fastcall force to put arguments in register when is possible

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites