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

Jon LaBadie jonfu at jgcomp.com
Fri Feb 26 20:09:30 UTC 2016


On Fri, Feb 26, 2016 at 08:31:07AM -0600, Ranjan Maitra wrote:
> Hi,
> 
> Disclaimer: This is clearly marked OT, with the only connection to this group being the fact that I am running F23 on a 20-core Dell T5810 @3.1 GHz each and 64 GiB memory. My OT queries over the past 13 years (almost) here have elicited great wealth of information so I am posing here.
> 
> So, I am trying to compare two kinds of methods in a C program. Both are written as efficiently as possible (assumed because no point otherwise). I would like to know which of these is more efficient. I have been using get_rusage but I was wondering whether there is a better way?
> 
> Separately, is there a way to get the number of floating point instructions in C? Both FLOPS and MIPS? 
> 
> Many thanks and best wishes,
> Ranjan

Its been ages so I may have faulty memory.

The compiler can generate code to "profile" a piece of code.
As I recall the profile included info on number of times a
function is entered, total time spent in the function, and
maybe min/max times in the function.

You only need to add the profile option for the code you are
interested in.  And perhaps at the link stage also.

Jon
-- 
Jon H. LaBadie                  jonfu at jgcomp.com


More information about the users mailing list