I'll comment that in some cases, optimized code can use hardware instructions for these operations, rather than the library calls you'll get in an unoptimized configuration. Also, optimization can reorder the expressions and may do a different series of operations than you have written in the code.
My general advice on such matters is to not try to code to a view of "which operations are fastest". Write the code in a natural fashion and allow the compiler to do its job. If you think performance needs to be improved, run a profiler to see where the hot spots are. Almost invariably, they aren't where you think.
Steve
Re: operation timing
如需更全面地了解编译器优化,请参阅优化注意事项.




Re: operation timing
This sort of thing is pretty difficult to answer precisely, I think your numbers give you a general idea, however other effects of optimization may still have an effect, depending upon how your code is structured. Obviously if you write code that the compiler determines is unnecessary, as in the case of your benchmark, that will change things substantially. If you are working with arrays that exceed your working set size, then again, this may "equalize" things a bit. Ultimately what you are shooting for is to write things as efficiently as you can, then use a profiling tool to see where the fat is for further improvements. There likely will be some hardware dependence as well for these relative timings.
One minor note, your EXP appears to be quite a bit more efficient relative to addition than on my setup.
James