Whitch way is faster?

Started by
6 comments, last by MetaKnight 20 years, 5 months ago
is this faster in runtime?: class myclass { void POOP() { //STUFF } }; or this?: class myclass { void POOP(); }; myclass:OOP() { //STUFF }
Advertisement
The first...by a few microseconds. The first way inlines it. That means that whenever the compiler comes across a call to the function, it will replace that call with the code that''s in the function. In the second way it jumps to the function. Inline it if you call it many times a frame, but otherwise it will just increase your exe size.
____________________________________________________________AAAAA: American Association Against Adobe AcrobatYou know you hate PDFs...
Actually, putting the function body in the class definition does not necessarily mean that the function will actually be inlined. The normal inlining requirements apply, e.g. no recursion, should be a short function, can't have a pointer taken to it, etc.

According to most C++ programmers you'd ask, the BETTER way to do it (when possible) is the second, because it allows you to separate interface from implementation. Changing stuff like this simply to wring a few more cycles out of your engine is a really bad idea. It's called "micro-optimzation". It's also called "premature optimization".

"Sneftel is correct, if rather vulgar." --Flarelocke

[edited by - sneftel on November 7, 2003 1:51:31 PM]
With .NET 2003 and link time code generation both are the same...
In practice. No difference at all!
quote:Original post by Sneftel
According to most C++ programmers you''d ask, the BETTER way to do it (when possible) is the second, because it allows you to separate interface from implementation. Changing stuff like this simply to wring a few more cycles out of your engine is a really bad idea. It''s called "micro-optimzation". It''s also called "premature optimization".


Being a C++ programmer, that is correct, but if you still want the inline effect, you can use the inline keyword on the function in the class to have it still tell the compiler you want it to be inline;

VLAjarn: Cause it (linux) NEVER crashesMrPr0Grmer: lol ur wrongMrPr0Grmer: RedHat crashesVLAjarn: I'm saying good builds of linux
awsome thanks!
quote:Original post by Newfound Ajarn
Being a C++ programmer, that is correct, but if you still want the inline effect, you can use the inline keyword on the function in the class to have it still tell the compiler you want it to be inline;


Most compilers ignore the inline keyword, except for forbidding you from taking a pointer to the function. It''s sort of like the register keyword.

"Sneftel is correct, if rather vulgar." --Flarelocke

This topic is closed to new replies.

Advertisement