Mail Archives: djgpp/1997/04/08/10:36:44
Tom Wheeley (tomw AT tsys DOT demon DOT co DOT uk) wrote:
: In article <3348B1FF DOT 167E AT gig DOT nl> bram AT gig DOT nl "Bram Stolk" writes:
: > > He is doing 50,000 calculations in a 'for' loop, not pausing.
: > > I'm sure this should be in the FAQ, as it's one of the
: > > important aspects that everyone needs.
: > When benchmarking:
: > Make sure, that the result of the calculations is used
: > afterwards (in a printf or so).
: > If you don't, a smart compiler will optimize it, and remove
: > the calculations entirely.
: > This is what happened to me, after writing a very naive
: > benchmark :-)
: > The smart compiler was Sun's cc.
: I was under the impression (can't remember where from) that gcc recognises
: such loops as being (somewhat innaccurate) timing loops, and so doesn't
: optimise them away.
True. Somewhere in the GCC.info-files. GCC is somewhat too smart here,
is you'ld ask me...
: BTW, using printf will introduce I/O into your benchmark, and that will
: become the dominant factor. Do something more useful like fill a very large
: array.
He meant to just print the value once after the loop has ended.
Because, if the computed value isn't used, it can be left out
completely.
--
Groeten, Michel. http://www.cs.vu.nl/~mdruiter
\----/==\----/
\ / \ / "Als je voetbalcriminaliteit wilt tegengaan,
\/ \/ moet je ophouden met voetballen", Nordholt.
- Raw text -