#### Archived

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

# Whitch way is faster?

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

## Recommended Posts

is this faster in runtime?: class myclass { void POOP() { //STUFF } }; or this?: class myclass { void POOP(); }; myclass:OOP() { //STUFF }

##### Share on other sites
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.

##### Share on other sites
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]

##### Share on other sites
With .NET 2003 and link time code generation both are the same...

##### Share on other sites
In practice. No difference at all!

##### Share on other sites
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;

awsome thanks!

##### Share on other sites
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