delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/04/08/10:36:44

From: mdruiter AT cs DOT vu DOT nl (Ruiter de M)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: I don't understand djgpp's optimizations
Date: 8 Apr 1997 10:23:23 GMT
Organization: Fac. Wiskunde & Informatica, VU, Amsterdam
Lines: 37
Message-ID: <5id6ar$9tk@star.cs.vu.nl>
References: <33440E51 DOT 6AE AT imaginet DOT fr> <5i38mc$36q AT news DOT epcc DOT edu> <334864E0 DOT 5EDE AT cynergy DOT com DOT au> <3348B1FF DOT 167E AT gig DOT nl> <860455955snz AT tsys DOT demon DOT co DOT uk>
NNTP-Posting-Host: sloep03.cs.vu.nl
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019