From: tomw AT tsys DOT demon DOT co DOT uk (Tom Wheeley) Newsgroups: comp.os.msdos.djgpp Subject: Re: I don't understand djgpp's optimizations Date: Mon, 07 Apr 97 23:32:35 GMT Organization: Adventures and Diving Message-ID: <860455955snz@tsys.demon.co.uk> 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> Reply-To: tw104 AT york DOT ac DOT uk Lines: 29 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp 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. 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. -- :sb)