3 ms·
-O3 is too smart, it optimizes away the loop and transforms the code into printf(the_result).
by FooBarWidget 16y ago
-O3 is too smart, it optimizes away the loop and transforms the code into printf(the_result).
- Groxx 16y agoHah, nice. Didn't check the resulting code. Know what the other optimization levels do? I'm don't really know x86 assembler. I do still side with the optimization though, in that the .NET-VM could do this as well. The loop is pretty simple, and can be optimized away. Why shouldn't it?
- bad_user 16y agoYour answer received lots of votes for what are basically assumptions. The author of the article updated his post for -O3 by using a volatile variable for the for-loop test, which makes the compiler not optimize away the loop. For .NET you can look at the generated assembly, and if it does optimize away the loop you can use the same trick. No reasons for guessing. We are software engineers after all.
- JoachimSchipper 16y ago"volatile" forces the C compiler to issue load and store instructions for each access (although real-world C compilers are notoriously buggy here), so it makes the loop much slower. That's not a fair comparison.