I'm in a game programming school and here we have to learn about code speed, something that seems important.
Are there any tutorial or list of things to be aware of when programming in C/C++ ?
I wonder about many things, like why the default behavior of C is by passing data rather than reference/address, or how the compiler translate a reference to the assembler, or how a C loop translates itself to JMP's.
I'm concerned about that because python uses another way, but on the other hand python doesn't use an operator to copy the value, rather a function which can be syntactically heavy.
I don't really think knowing how to program in assembly is really is necessary, since it's painful, I guess it's just required to know about a register etc.
Look up your compiler's documentation for the switch to output the asm step rather than machine code. Every compiler I've worked with has one. Use it to send some simple code to asm and examine it.
VS also has the option to 'view assembly' as you step through code.
There's not going to be any clear answer to your question. It's all dependent on the compiler and the architecture. Even on the arguments supplied to the compiler.
Edit:
The fact that there's no clear answer to your question won't stop people from making things up. One example is silly things like passing a large object (like a string :p) by reference instead of returning by value. These things will seem reasonable to a new C++ developer. OF COURSE passing a string into a function to get filled is faster than building a copy and returning it from that function only to copy it again in assignment. Fact of the matter is that it doesn't work that way though; it's very compiler dependent but you could be stomping all over your compiler's ability to optimize by trying to get all smart.
There's TONS of misinformation out there about making your code fast. Take it all with a grain of salt. Most people who claim to know how to make fast code are full of crap. The only reasonable answer to fast code is to profile your code. When it comes time to micro-optimize you'll be doing a bunch of stuff that's very specific to your target platform. General knowledge, "this is faster," stuff won't be of any use to you at that point.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With