Re: Function Timer in C
On Apr 6, 7: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.
It's CLOCKS_PER_SECOND. Posix requires CLOCKS_PER_SECOND to be
1000000, but it may vary on other systems. The best way to
write the above would be:
std::cout << "Elapapsed time: "
<< double( End - Start ) / CLOCKS_PER_SEC * 1000.0
<< " ms" << std::endl ;
On my system it's 1/1000 of a second.
In the old days, 50 or 60 used to be frequent values.
--
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