Re: Function Timer in C
On Apr 9, 4:11 am, "Siddhartha Gandhi" <siddharthagandhi...@gmail.com>
wrote:
On Apr 6, 1:06 am, "Jim Langston" <tazmas...@rocketmail.com> wrote:
<yoviesma...@gmail.com> wrote in message
news:1175757910.094696.10680@w1g2000hsg.googlegroups.com...
I have a problem with C programming. I want to make function timing
in C, but I don't know how the function or the algorithm. so, I need
your help to giveme information about it. Thanks.. for your
attention... see.. you..
I generally just use clock().
unsigned int Start = clock();
MyFunction();
unsigned int End = clock();
std::cout "Elapapsed time: " << End - Start << " ns" << "\n";
Modify to taste. I think it's ms. On my system it's 1/1000 of a secon=
d.
On most systems it is a millisecond.
On all systems, it's CLOCKS_PER_SEC. Other than that, the only
"standard" I know is Posix, which requires a value of 1000000
for CLOCKS_PER_SEC, i.e. microseconds. (Linux is also Posix
conform in this respect.)
I use std::clock() as well,
margin of error of close to 10 milliseconds, though.
Historically, the granularity was the number of ticks. This
certainly isn't the case today, and I don't know of any system
which really gives microsecond granularity. (Historically, on
the first systems I used, CLOCKS_PER_SEC was 50 in Europe, and
60 in America. Which was the granularity.)
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34