Solved

Measuring time diffrence in micro seconds

Posted on 2001-06-27
4
400 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Why You Need a DevOps Toolchain

IT needs to deliver services with more agility and velocity. IT must roll out application features and innovations faster to keep up with customer demands, which is where a DevOps toolchain steps in. View the infographic to see why you need a DevOps toolchain.

Question has a verified solution.

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

In our personal lives, we have well-designed consumer apps to delight us and make even the most complex transactions simple. Many enterprise applications, however, are a bit behind the times. For an enterprise app to be successful in today's tech wo…
Invest in your employees with these five simple steps to improve employee engagement and retention.
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.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

707 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