Solved

Timer function in C++

Posted on 2004-04-17
4
38,767 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

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

Suggested Solutions

Title # Comments Views Activity
Object Data Source 4 124
Custom ckeditor using builder 10 94
Nest Related files not working in Visual Studio 4 76
egit plugin on eclipse 8 33
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

911 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

18 Experts available now in Live!

Get 1:1 Help Now