- Is there any difference between > and >=, speed-wise? For example:
Code: Select all
if (myvar > 1) somefunction();
Code: Select all
if (myvar >= 2) somefunction();
Code: Select all
if (myvar > 1) somefunction();
Code: Select all
if (myvar >= 2) somefunction();
Thanks.Well it may depend on the instruction set of the processor you're using, on x86 processors there are instructions for testing > or >= with the same execution cycle numbers.
Do you mean 128 bits (FFFF FFFF hex, 4 294 967 295 dec)?Another factor is the size of the immediate value eg the sh4 can only compare -128-127 so if you said >=128, the compiler (or you) would have to hack a little bit to avoid storing 128 in memory.
Thanks. It's just that I tend to be nitpick when I'm working .Such worries are not as important as a clear program. Most programs I've seen use the > notation so you should use that.
Using the code "directly" is faster, but there's a keyword -inline- you can use before a funcion declaration for the compiler to put the code of the function "directly" where the call is, and also when you enable optimization options, compilers auto-inline functions they consider. For extremely simple things, you can also use macros instead of functions.Fragger wrote:Is there any speed difference between calling a function and using the code "directly"?
I think simple macros are still pretty useful when coding for systems with limited resources (like DC, consoles like GBA, embedded systems, etc.). It's true you have to be very careful when working with macros (put all the input parameters in brackets, do all kind of castings, etc) but it it's fast, easy and works, why shouldn't I use it?nymus wrote:doragasu wrote:Most programmers today frown on the use of using macros in working/executable code. Leave macros for configuration.Fragger wrote: For extremely simple things, you can also use macros instead of functions.
I just want to chime in here on this because while your question was answered, I felt the "why" was left out.Fragger wrote:Is there any speed difference between calling a function and using the code "directly"?