Jump to content
  • Advertisement

Archived

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

Arch@on

The fastest type of funtion?

This topic is 5547 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

What is the fastest function in C? Static void? What about the fastest member function in C++? Inline static void?

Share this post


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

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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!