Click to See Complete Forum and Search --> : measuring milli/microseconds in VC6++


yoshi273
02-07-2002, 05:42 PM
got any ideas how to do it? Cant seem to find a decent function for it... thanks guys

biosx
02-07-2002, 06:14 PM
Yoshi,

I am not sure what is in the STL for C++ (I know the stadard library for C), but look around in the time.h header for some things. That is the only place I can think of.

Let me know if you find anything.

Good luck

------------------
## root is the greed of all evil ##

yoshi273
02-07-2002, 07:15 PM
alright, thanks bro - ill have a look

DeadKen
02-07-2002, 07:46 PM
Originally posted by yoshi273:
alright, thanks bro - ill have a look

For milliseconds, look up GetTickCount.

If you need better, look up QueryPerformanceCounter and QueryPerformanceFrequency.

I've only needed them once, but they were easy enough to use (though you need to link with some multimedia stuff I think).


------------------
I want an OS, not a hobby...

Ramuman
02-07-2002, 10:24 PM
Try this:

#include <time.h>
...
clock_t tv1, tv2; <-create any two variables of type clock_t
...
tv1 = clock(); <- initial time
...
tv2 = clock(); <-final time


time1=((tv2 - tv1)/(CLOCKS_PER_SEC / (double) 1.0)); <-time1 can be any double or float and it'll hold the difference between tv2 and tv1.

CLOCK_PER_SEC is a predefined constant in the time header with a value 1000. The code I listed will give you the time down to milliseconds and put it in time1. To get different units of time, change the 1.0 to other units (say 60 for minutes). I hope that helps http://www.sharkyforums.com/ubb/smile.gif


EDIT: I almost forgot, make sure you're running this on a CPU of at least a few hundred MHz. It will work on slower CPUs, but the way it does it, it has a tendency to loose accuracy over a long period of time if the CPU is exceedingly slow (perhaps a 286 or 386 or slower).
------------------
Formerly bobgod007

[This message has been edited by Ramuman (edited February 07, 2002).]

yoshi273
02-08-2002, 12:45 AM
Thank you all

DeadKen
02-08-2002, 01:11 AM
Originally posted by Ramuman:
Try this:

#include <time.h>
...
clock_t tv1, tv2; <-create any two variables of type clock_t
...
tv1 = clock(); <- initial time
...
tv2 = clock(); <-final time


time1=((tv2 - tv1)/(CLOCKS_PER_SEC / (double) 1.0)); <-time1 can be any double or float and it'll hold the difference between tv2 and tv1.

CLOCK_PER_SEC is a predefined constant in the time header with a value 1000. The code I listed will give you the time down to milliseconds and put it in time1. To get different units of time, change the 1.0 to other units (say 60 for minutes). I hope that helps http://www.sharkyforums.com/ubb/smile.gif


EDIT: I almost forgot, make sure you're running this on a CPU of at least a few hundred MHz. It will work on slower CPUs, but the way it does it, it has a tendency to loose accuracy over a long period of time if the CPU is exceedingly slow (perhaps a 286 or 386 or slower).

This is a sad implementation for Windows. If Microseconds is your goal, I doubt this will get you close. Go with the hi-res times.

The time.h stuff uses code which probably uses GetClockTicks. Too much overhead for high accuracy timing.




------------------
I want an OS, not a hobby...