I found that, when comparing a variable to a constant, without optimization the if method is faster by two instructions or just as fast; with optimization was harder to measure because the optimizer was rather aggressive and kept merging the if with the call to cout.operator<<. The optimized direct assignment (variable=(variable<constant)) only took two instructions, but wasn't merged with the call, so it might take more.
When comparing a variable to another variable, everything took more or less the same time, both optimized and unoptimized.
Personally, I prefer direct assignment because it makes clearer what the code is doing, besides making it terser, and a few clocks is a small sacrifice.
I have to agree with helios here. None of the options presented will really ever have a significant effect on the execution time of your program. Algorithms tend to be the things that slow programs down, not semantic choices. Go with whatever is most readable to you.
I found that, when comparing a variable to a constant, without optimization the if method is faster by two instructions or just as fast;
Counting the number of asm instructions generated by the compiler is not a viable method for determining speed. Since Pipeling was introduced and memory and OS have things like "read-ahead' and predictive execution it's really impossible to tell the speed of any piece of code without running it against a timer. Having that 1 extra instruction is like throwing a pebble into the ocean as far as optimisation is concerned anyways. But that extra instruction could be a catalyst for a bigger speed increase.
Technically, since C++ is supposed to be portable, we shouldn't even be reading disassembly to try to figure out which is faster, because there's no way to know (or rather, we shouldn't know) what kind of code a compiler will produce for a given CPU. Like rossman said, we should rely more on macro optimizations such as better algorithms or data structures than on micro optimizations, which the compiler is better at, anyway.
Thanks for that Zaita and Helios. Only other question other than that is. Should one be used over the other one or it really won't change anything. Let that be up to your employer :P