Solved

Timer function in C++

Posted on 2004-04-17
4
38,776 Views
Last Modified: 2013-11-17
I am using alarm() to time a process.

Is there something with which i can measure by milliseconds ?

The alarm() in C++ allows only seconds and not anything lesser than that.

I did try ftime() and time(),But i need something to timeout automatically.

Thanks
0
Comment
Question by:karthikram
  • 2
4 Comments
 
LVL 9

Expert Comment

by:Cayce
ID: 10849712
What OS/Platform are you using?
What compiler?
0
 

Author Comment

by:karthikram
ID: 10849768
RH Linux with a g++ compiler 3.2
0
 
LVL 9

Accepted Solution

by:
Cayce earned 125 total points
ID: 10849912
Why you post in the C++Builder forum then? ;)

Just kidding, however, the PTimer class sounds like a good idea to me.
There's some documentation  to it in: http://www.openh323.org/docs/PWLib/PTimer.html. This class comes with pwlib-devel, you can easily get it using red carpet.

OR use POSIX timers, check http://www.nd.edu/~lemmon/courses/UNIX/l4a/node9.html. Which is a good idea for portability.
0
 

Expert Comment

by:Mike1975
ID: 10886163
//Try this!!!
LONGLONG Frequency, CurrentTime, LastTime;
    double TimeScale;

QueryPerformanceFrequency( (LARGE_INTEGER*) &Frequency);
TimeScale = (1.0/Frequency)*1000.0;

QueryPerformanceCounter( (LARGE_INTEGER*) &LastTime);//begin measure

//Add the function in here

QueryPerformanceCounter( (LARGE_INTEGER*) &CurrentTime);//end measure
AnsiString milliseconds = (CurrentTime-LastTime)*TimeScale;
//difference in milliseconds is (CurrentTime-LastTime)*TimeScale
0

Featured Post

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

772 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