<> wrote in message
news: oups.com...
> Thanks everybody. It was helpful.
>
> Actually I had implemented an algorithm and when I compile my proram
> with -O it is much faster whereas when I compile the code of my
> comparators with -O it doesn't have any effect on their running time.
> What may be the reason?
That is a bit strange; I've never run across code that doesn't improve _at
all_ when optimized, but I'm sure it's possible.
If one writes the most obvious (and correct) code to solve a problem, it
will likely run slowly without optimization, but when optimization is
enabled the compiler should be able to make it go much faster. If one
writes very tight, slightly incorrect code, the compiler may not be able to
speed it up without breaking it, and so it can't help.
As the saying goes, "it's a lot easier to make correct code fast than it is
to make fast code correct."
> Is it fair to compare the running time using optimization?
Depends why you're comparing. In most cases, software is compared with the
highest optimization level that results in correct code.
> As suggested, optimization may lead to wrong output so if this happen
> does this mean that their was something wrong in implementation ? or
> wat?
It depends. If the code is correct, odds are wrong output is caused by a
compiler bug; however, unless one is a very good coder, there's a much
higher chance that the code was not correct in the first place and the more
aggressive optimization levels merely exposed bugs that were there all
along.
If you don't know how to determine which of those applies to your code,
assume that the bug is yours, not the compiler's.
S
--
Stephen Sprunk "Stupid people surround themselves with smart
CCIE #3723 people. Smart people surround themselves with
K5SSS smart people who disagree with them." --Aaron Sorkin
--
Posted via a free Usenet account from
http://www.teranews.com