Timespan calculations

C

Clive

Hi,
I'm hoping someone can help -
I want to see how long some code is taking to execute, & then print out the result.
Do I have to use GetSystemTime twice & then do some maths?
So example code wuold be great.

Thanks in advance,
Clive
 
J

John Harrison

Clive said:
Hi,
I'm hoping someone can help -
I want to see how long some code is taking to execute, & then print out the result.
Do I have to use GetSystemTime twice & then do some maths?

GetSystemTime is not a standard C++ function.
So example code wuold be great.

#include <time.h>

time_t t0 = time(0);
/* some long calculation */
time_t t1 = time(0);
double time_in_seconds = difftime(t1, t0);
Thanks in advance,
Clive

Its usually better to use standard functions, time_t, time and difftime are
all standard functions which will be available on any platform with a
standard C or C++ compiler.

john
 
K

Kevin Goodsell

John said:
Its usually better to use standard functions, time_t, time and difftime are
all standard functions which will be available on any platform with a
standard C or C++ compiler.

But the resolution of those might be too low to be useful for code
timing. Better to use a real profiler, I'd say.

-Kevin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top