There’s a good chance that the ternary operator gets compiled into a cmov
while the if/else results in a cmp
+jmp
. Just take a look at the assembly (using -S) to be sure. With optimizations enabled, it won’t matter any more anyway, as any good compiler should produce the same code in both cases.
More Related Contents:
- Is there a performance difference between i++ and ++i in C++?
- Why are elementwise additions much faster in separate loops than in a combined loop?
- How to write a large buffer into a binary file in C++, fast?
- Why is my program slow when looping over exactly 8192 elements?
- What is the efficient way to count set bits at a position or lower?
- Virtual functions and performance – C++
- mixing cout and printf for faster output
- What’s your favorite profiling tool (for C++) [closed]
- Is there any guarantee of alignment of address return by C++’s new operation?
- Using AVX CPU instructions: Poor performance without “/arch:AVX”
- What’s faster, iterating an STL vector with vector::iterator or with at()?
- Why does GCC generate 15-20% faster code if I optimize for size instead of speed?
- Fast Cross-Platform C/C++ Image Processing Libraries
- Getting an accurate execution time in C++ (micro seconds)
- Why is std::unordered_map slow, and can I use it more effectively to alleviate that?
- Can the use of C++11’s ‘auto’ improve performance?
- What is the fastest way to change a key of an element inside std::map
- Why is std::fill(0) slower than std::fill(1)?
- Efficiency of the STL priority_queue
- Performance of qsort vs std::sort?
- What’s the fastest way to pack 32 0/1 values into the bits of a single 32-bit variable?
- Writing function definition in header files in C++
- Is Python faster and lighter than C++? [closed]
- Why can’t I use a “break” statement inside a ternary conditional statement in C++?
- Hashtable in C++?
- Does auto deduce the type at compile time or runtime in C++ 11?
- Measuring exception handling overhead in C++
- Why do I see 400x outlier timings when calling clock_gettime repeatedly?
- What is the modern, correct way to do type punning in C++?
- Why is this C++ wrapper class not being inlined away?