Link to home
Start Free TrialLog in
Avatar of harisnshaw
harisnshaw

asked on

Measuring time diffrence in micro seconds

How do i measure time diffrence of micro seconds in turbo C++. The time.h can find max diffrence in ms only.
Avatar of agriggs
agriggs

Use QueryPerformanceFrequency to get the frequency of the high-resolution timer, if one exists on the system.  The value returned is the number of ticks per second.  If no high-resolution timer exists on the system, then the value will be zero.

Then use QueryPerformanceCounter to get the number of ticks.  Then call QueryPerformanceCounter again to get the number of ticks at some later point in time.  Then subtract to get the difference.

Avatar of ambience
QueryPerformanceXXX will not be callable thru Turbo C++ i think , one way is to use clock()

clock_t start, finish;
double  duration;
start = clock();
finish = clock();
duration = (double)(finish - start) / CLOCKS_PER_SEC;

to get into microseconds multiply it by 10^6. This may work out to be an approximation.. code may not be portable !!!
ASKER CERTIFIED SOLUTION
Avatar of AlexVirochovsky
AlexVirochovsky

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
clock() actually returns the amount of elapsed cpu time the calling processed used. Of course, if you're running this on just a DOS machine, it will be good enough. If, however, you're just in a DOS window, your results will very since the OS will likely suspend your process periodically to turn the cpu over to other processes.

biostime is a good option (as is INT 0x1A) - just keep in mind that they are definitely not portable. But I don't imagine that will be an issue here.