Solved

Measuring time diffrence in micro seconds

Posted on 2001-06-27
4
393 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
Comment
Question by:harisnshaw
4 Comments
 
LVL 2

Expert Comment

by:agriggs
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

by:ambience
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

by:
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

by:wkmatt42
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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If your app took Google’s lash recently, here are the 5 most likely reasons.
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
XMind Plus helps organize all details/aspects of any project from large to small in an orderly and concise manner. If you are working on a complex project, use this micro tutorial to show you how to make a basic flow chart. The software is free when…

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

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

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now