From: "John S. Fine" Newsgroups: comp.os.msdos.djgpp Subject: Re: timing with empty loops -- small green ufo-s? Date: Sat, 20 Feb 1999 11:10:52 -0500 Lines: 31 Message-ID: <36CEDE8C.27D2@erols.com> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: lc1jSOUHL2mYqXOE7H4pJyxcHyq5X1BYip7JDLVuJVs= X-Complaints-To: abuse AT rcn DOT com NNTP-Posting-Date: 20 Feb 1999 16:12:12 GMT X-Mailer: Mozilla 3.01 (Win95; U) To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Engard Ferenc wrote: > My program does it's timing with empty loop: > > void do_delay (unsigned long i) > { while(i--) ; } > > The calibration is nearly the same as the linux-kernel bogomips-computing > (actually, I have copied it from there... :-) I never looked at the linux version, but I have tested such routines several times while advising various people doing write-your-own-OS projects. Generally, this method of timing is so full of pitfalls that I advise against using it. At minimum, it is heavily dependant on the memory alignment of the code itself. (I don't know whether it may be suffitiently nonoptimized by GCC switches that it could also depend on the memory alignment of the stack). At minimum you must calibrate it on startup and you MUST use the routine itself in its own calibration. The common method of calibrating with a similar (or even identical) loop elsewhere in the code, is unsound. After proper calibration, this method *might* work. If you have another reasonable choice, you shouldn't use this method at all. -- http://www.erols.com/johnfine/ http://www.geocities.com/SiliconValley/Peaks/8600/