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

Ranjan Maitra maitra.mbox.ignored at inbox.com
Fri Feb 26 15:51:24 UTC 2016


Thanks!

On Fri, 26 Feb 2016 10:16:18 -0500 Tom Horsley <horsley1953 at gmail.com> wrote:

> On Fri, 26 Feb 2016 08:31:07 -0600
> Ranjan Maitra wrote:
> 
> > I have been using get_rusage but I was wondering whether there is a better way?
> 
> You most accurate wall time is going to come from looking at
> the TSC register (if you are on an x86 processor)
> 
> https://en.wikipedia.org/wiki/Time_Stamp_Counter
> -- 

Yes, I am on an x86_64 Intel processor.

So, here is the problem I am having. I tried running the following timing program:

https://github.com/ChisholmKyle/PosixMachTiming

with the value in the loop increased to UINT_MAX to get better precision. (It also uses clock_gettime().) 

And then I run it twice but get different precisions. How does this happen? The number of operations are exactly the same (or should be). 

Many thanks and best wishes,
Ranjan

____________________________________________________________
FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family!
Visit http://www.inbox.com/photosharing to find out more!




More information about the users mailing list