OT: recommended way of timing two pieces of code in C

Patrick O'Callaghan pocallaghan at gmail.com
Sat Feb 27 00:41:54 UTC 2016


On Fri, 2016-02-26 at 17:31 -0700, jd1008 wrote:
> 
> On 02/26/2016 05:28 PM, Ranjan Maitra wrote:
> > 
> > Thanks again!
> > 
> > > 
> > > > 
> > > > OK, is there a way to calculate the FLOP instructions in C?
> > > What do you mean "calculate the FLOP instructions"? Are you
> > > trying to
> > > evaluate an algorithm or benchmark an implementation? These are
> > > two
> > > different things. You can compare algorithms theoretically or by
> > > measurement, but only measurement will work for implementations.
> > > You
> > > can count each floating point instruction generated by the
> > > compiler by
> > > looking at the binary code, but maybe you want to count every
> > > instruction during execution, or see which instructions take
> > > longer, or
> > > just measure the total execution time of the algorithm on a given
> > > set
> > > of input.
> > Indeed, I wanted to measure the total execution time of the
> > algorithms (i.e. difference in CPU time after and before the
> > function executing the algorithm is called) and independent of
> > extraneous issues such as what other process is running at some
> > time, etc. I wanted to see if, in some case, some of the available
> > theoretical guarantees actually hold or not.
> > 
> > Thanks again!
> > 
> > Best wishes,
> > Ranjan
> > 
> Did you see my reply?
> It shows you the basics of what you need to use
> in order to get exactly what you want.

Note that the accuracy of this depends on several factors, such as how
long the measured interval is compared to the basic unit of timekeeping
(IOW if you want to measure the execution time of a short sequence of
instructions, you need to loop a few million times and divide the
result), and how much overhead is incurred in calling the timing
routines. 

poc


More information about the users mailing list