View Full Version : What is faster: ? or If (C)
Ricardo_V
08-30-2006, 01:43 PM
hello,
Is it faster to use the ? operator or an IF sentence?
Is there any good website where I can find information related to that kind of topics?
thanks in advance
Bludd
08-30-2006, 03:39 PM
Can't you do some performance testing yourself? Many IDEs have this feature.
There would be something very wrong with the compiler if one of them was significantly faster than the other. I suppose it's only syntactic sugar (http://en.wikipedia.org/wiki/Syntactic_sugar), and it doesn't affect performance. By the way, the ? operator is very useful in C++ class constructor initializer expresions, but that's a different matter, as in that case it really increase language expressiveness.
Destroyer
08-30-2006, 11:40 PM
I think rg3 said it right. shouldnt make a huge difference, and even if 1 is slightly faster then the other I think it might depend on the compiler.
I say use whatever you whish. make the optimizations when it comes to algorithms, thats where choosing a faster option can make a huge difference.
Jiminator
08-31-2006, 02:00 AM
remember that ? is a type specific expression, if is not. a secondary issue is with code maintainibility, if you nest multiple ? expressions then it can become hard to figure out what is what. anyway cpus are so fast today that either one will not make much of a difference, it is the library/os calls that do the performance hit. (unless you are doing serious math).
vBulletin® v3.8.0, Copyright ©2000-2009, Jelsoft Enterprises Ltd.