Originally posted by: JimMcInnes
I got
curious about what the real speedup is
from using -O2, so I did a few
runs on an old machine we have sitting
around in our shop. I used XLC
V11.1 and XLF V13.1 to measure the old
SPEC CPU2000 benchmark suite. I did
two measurements: one with -O2 and one
without optimization. The results are
presented below in a table and they
confirm what I suspected – Code
compiled with -O2 consistently performs 2-3
times faster than the same code compiled
without optimization! This
is a big difference! Maybe if you
optimize you can get more life out of
your current hardware. Here are the
details:
I
know that using optimization has its
negative points also. Let me try to
address a couple of those.
The
main one I hear is that it hinders
debugging. Certainly, some symbols are
hidden from the debugger (by maybe keeping
the value in a register for its whole
life so there is no memory location for
the debugger to check) or also by
messing up line numbers (when common
subexpressions are discovered from different
lines, which line number should be used?)
In fact there are probably a hundred
things that the optimizer does to confuse
the debugger, but still I manage to
debug my optimized code. In extreme
cases, I rely on a trick we use
when building the compiler: we always
do two builds from the same sources,
one optimized and one not. They should
show the same behaviour (if not then
you have a compiler bug!) so you can
debug the noopt one and use the opt
version in production.
The
other complaint is compile time. Of
course the build with -O2 will take
longer because the compiler is doing more
work. For -O2, I think most
programmers will find the difference acceptable,
though. Usually the compile happens once
and the resulting executable is run many
times, so the difference is paid back.
SPEC
CPU2000, SPECfp and SPECint are trademarks
of the Standard Performance Evaluation
Corporation (SPEC). Please see
http://www.spec.org
for more information.