LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 04-20-2002, 02:14 PM   #1
Hano
Member
 
Registered: Sep 2001
Location: Venezuela, Caracas
Distribution: RedHat 9.0
Posts: 196

Rep: Reputation: 30
measuring time


Hi,



How do you measure time between events in linux?
are there any nice and short functions you can write?


Hano
 
Old 04-20-2002, 06:25 PM   #2
zmedico
Member
 
Registered: Feb 2002
Location: Mission Viejo, California, USA
Distribution: Gentoo
Posts: 707

Rep: Reputation: 30
Most languages have time functions built in. For instance, Java has a System.currentTimeMillis() method that gives you the time in milliseconds.

My RedHat 7.2 installation came with kdevelop-2.0-1
That includes these nice references for C and C++ functions

/usr/share/doc/HTML/en/kdevelop/reference/C/cref.html
/usr/share/doc/HTML/en/kdevelop/reference/CPLUSPLUS/cref.html

Last edited by zmedico; 04-21-2002 at 01:06 AM.
 
Old 04-21-2002, 12:48 AM   #3
Hano
Member
 
Registered: Sep 2001
Location: Venezuela, Caracas
Distribution: RedHat 9.0
Posts: 196

Original Poster
Rep: Reputation: 30
hey, i end up answering myself again...

i did this C++ class as a chronometer, so enjoy everyone:

#include <sys/timeb.h>

class chronometer {
private:
struct timeb start_time;
struct timeb end_time;
int state;
int aux;
int sec;
int msec;
float total_seconds;

public:
chronometer(){state=0; };
~chronometer() {};

void start() {
reset();
state=1;
aux=ftime(&start_time);
};

void stop() {
aux=ftime(&end_time);
if (state==1) {
state=0;
total_seconds+=elapsed_time();
};
};

void restart() {
stop();
state=1;
aux=ftime(&start_time);
};

void reset() {
total_seconds=0.0;
};

float read_time() {
if (state==1) {
stop();
state=1;
aux=ftime(&start_time);
};
return total_seconds;
};

float elapsed_time() {
float seconds;
sec=end_time.time-start_time.time;
msec=end_time.millitm-start_time.millitm;
if (msec<0) {
sec--;
msec+=1000;
};
seconds=((float)msec )/1000;
seconds+=sec;
return seconds;
};

};


using it is easy and straightforward, just:

chronometer myclock;
myclock.start(); //start chronometer
//do whatever you want to clock
cout<<" have been up "<<myclock.read_time()<<"seconds "<<end;
myclock.stop(); //pause chronometer
//bla bla bla
myclock.restart(); //restart

...and so on

Hano

Last edited by Hano; 04-21-2002 at 12:56 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
measuring Bandwidth lumba General 1 11-21-2005 07:01 AM
measuring the internet bandwidth supersucker Linux - Newbie 1 09-01-2005 07:59 AM
Network Measuring Tool Panman Linux - Software 3 07-20-2005 06:53 AM
measuring network activities raees Linux - Networking 1 04-24-2005 01:26 PM
Measuring internet tarffic gubak Linux - Networking 4 01-15-2005 01:49 AM


All times are GMT -5. The time now is 11:31 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration