Title: System time function in visual c 6.0
revenant - January 12, 2007 01:33 PM (GMT)
i've got a Algorythm Analisis project to do , and i need to know if there is a function that returns the system time in miliseconds, or a function group that counts miliseconds during the execution o a set of instructions( like tic() toc() in matlab )
looking through visual c headers i found the _ftime() fuction that returns a timeb structure which looks like this :
struct _timeb {
time_t time;
unsigned short millitm;
short timezone;
short dstflag;
};
how can i acces the millitm memeber? (program snippet please)
thanks in advance wink2.gif
C-Man - January 12, 2007 01:34 PM (GMT)
clock () in <ctime> or <time.h> returns miliseconds since the program was started if that is suitable for your needs
revenant - January 12, 2007 02:01 PM (GMT)
10x c-man but it doesn't help since the user will be interacting with a menu :(
i need to determine how long it takes to run different functions
Ravotus - January 12, 2007 02:33 PM (GMT)
That's easy. Simply put the current system time in a variable, run your function, then get the new system time. Subtracting the old from the new will give you the (very approximate) time it took for that function.
Remember, though, that if you're timing small function calls in only milliseconds it won't be the most accurate, but it will get the job done.
C-Man - January 12, 2007 03:00 PM (GMT)
you can do the same with using clock ()
since you only need the time difference , doesn't matter to what the time is relative to
revenant - January 12, 2007 08:29 PM (GMT)
the problem was that i need the time in miliseconds and clock() returns a structure without the milliseconds data member....someone gave me the solution so i'll post it here in case someone needs it :
first include :
#include <sys/timeb.h>
#include <time.h>
and the code snippet :
struct _timeb timebuffer;
_ftime( &timebuffer );
cout<<"milisecunde "<<timebuffer.millitm;
C-Man - January 12, 2007 08:36 PM (GMT)
clock returns in clock ticks , and to get milliseconds you just
(clock () * 1000) / CLOCKS_PER_SEC
http://www.cplusplus.com/reference/clibrary/ctime/clock.html