?
Solved

Measuring time diffrence in micro seconds

Posted on 2001-06-27
4
Medium Priority
?
403 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 400 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

Question has a verified solution.

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

This guide will walk you through the essential considerations and tech stack for building scalable websites. Know how to grow your business the smart way!
There are many software programs on offer that will claim to magically speed up your computer. The best advice I can give you is to avoid them like the plague, because they will often cause far more problems than they solve. Try some of these "do it…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

762 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