Solved

# Measuring time diffrence in micro seconds

Posted on 2001-06-27
390 Views
Last Modified: 2013-11-15
How do i measure time diffrence of micro seconds in turbo C++. The time.h can find max diffrence in ms only.
0
Question by:harisnshaw
4 Comments

LVL 2

Expert Comment

ID: 6233862
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.

0

LVL 22

Expert Comment

ID: 6234378
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 !!!
0

LVL 14

Accepted Solution

AlexVirochovsky earned 100 total points
ID: 6236780
Only way, that I know, use biostime function:
biostime

...
#include <bios.h>
long biostime(int cmd, long newtime);

Description

Reads or sets the BIOS timer.
biostime either reads or sets the BIOS timer. This is a timer counting ticks since midnight at a rate of ticks per second as defined by _BIOS_CLOCKS_PER_SEC. biostime uses BIOS interrupt 0x1A.
If cmd equals 0, biostime returns the current value of the timer. If cmd equals 1, the timer is set to the long value in newtime. For example:

totalsecs = biostime(int cmd, long newtime) / _BIOS_CLK_TCK;

The _BIOS_CLOCKS_PER_SEC and _BIOS_CLK_TCK constants are defined in bios.h.

Return Value

When biostime reads the BIOS timer (cmd = 0), it returns the timer's current value.
...

Of course, you can direct use 0x1A interruption:
with same results.
0

Expert Comment

ID: 6236868
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.
0

## Join & Write a Comment Already a member? Login.

Let’s list some of the technologies that enable smooth teleworking.
Skype is a P2P (Peer to Peer) instant messaging and VOIP (Voice over IP) service – as well as a whole lot more.
Using Adobe Premiere Pro, the viewer will learn how to set up a sequence with proper settings, importing pictures, rendering, and exporting the finished product.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

#### 760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

#### Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!