By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,418 Members | 1,104 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,418 IT Pros & Developers. It's quick & easy.

ctime Help

P: n/a
Hello:

I am trying to find documentation on using the ctime library as I need
to be able to instantiate an object to keep track of the time when a
certain event occurs. I also need to be able to take two of those
objects and perform calculations on them like: the time difference,
summing them, getting the mean time between events, etc.

Is ctime what I should be using?
Is there a better way?
Is there an clock or counter object that would act as a stopwatch and
continually run from instantiation while other code is executing?

I am trying to write a simulation program for a class project and I
have to calculate the time between events, but I am not sure how to go
about using some kind of timing object.

If you have any suggestions, I would appreciate them. I am not asking
anyone to write the program for me, just give me some direction as to
help me avoid mistakes and inefficient coding.

Thank you in advance.

Kevin
Jul 22 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On 15 May 2004 18:48:17 -0700, ke****@digimindz.com (Kevin) wrote:
Hello:

I am trying to find documentation on using the ctime library as I need
to be able to instantiate an object to keep track of the time when a
certain event occurs. I also need to be able to take two of those
objects and perform calculations on them like: the time difference,
summing them, getting the mean time between events, etc.

Is ctime what I should be using?
Is there a better way?
Is there an clock or counter object that would act as a stopwatch and
continually run from instantiation while other code is executing?

I am trying to write a simulation program for a class project and I
have to calculate the time between events, but I am not sure how to go
about using some kind of timing object.

If you have any suggestions, I would appreciate them. I am not asking
anyone to write the program for me, just give me some direction as to
help me avoid mistakes and inefficient coding.

Thank you in advance.


If you snarf any version of my InitUtil library from
http://www.bdsoft.com/tools/initutil.html
you'll find it comes packaged with a header file full of nifty STL
utilities (written by Scott Meyers, who has kindly given me permission to
distribute it). Among them is a simple little "Timer" class that let's you
query how much time has elapsed since each instance has been instantiated.
You may get some useful techniques/ideas from that. It is even fairly
portable.
-leor

--
Leor Zolman --- BD Software --- www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: download BD Software's free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html
Jul 22 '05 #2

P: n/a
Ian
Kevin wrote:
Hello:

I am trying to find documentation on using the ctime library as I need
to be able to instantiate an object to keep track of the time when a
certain event occurs. I also need to be able to take two of those
objects and perform calculations on them like: the time difference,
summing them, getting the mean time between events, etc.

Is ctime what I should be using?
Is there a better way?
Is there an clock or counter object that would act as a stopwatch and
continually run from instantiation while other code is executing?
ctime and friends only work in seconds, so if you require more accuracy,
you will have to use a platform specific API to read the system time.

It also depends on whether you want a periodic wakeup, or to time based
on other external events.

All platforms will have a methods of implementing stopwatch type
functionality - post to a group for your platform for information on how
to do this.
I am trying to write a simulation program for a class project and I
have to calculate the time between events, but I am not sure how to go
about using some kind of timing object.
Sounds like you will require a hi-res timer? If so this will be
platform specific.

If you're not sure where to look, post back with your platform and
someone will point yo in the right direction.

Ian
If you have any suggestions, I would appreciate them. I am not asking
anyone to write the program for me, just give me some direction as to
help me avoid mistakes and inefficient coding.

Thank you in advance.

Kevin

Jul 22 '05 #3

P: n/a
Kevin writes:
I am trying to find documentation on using the ctime library as I need
to be able to instantiate an object to keep track of the time when a
certain event occurs. I also need to be able to take two of those
objects and perform calculations on them like: the time difference,
summing them, getting the mean time between events, etc.

Is ctime what I should be using?
Is there a better way?
Is there an clock or counter object that would act as a stopwatch and
continually run from instantiation while other code is executing?

I am trying to write a simulation program for a class project and I
have to calculate the time between events, but I am not sure how to go
about using some kind of timing object.

If you have any suggestions, I would appreciate them. I am not asking
anyone to write the program for me, just give me some direction as to
help me avoid mistakes and inefficient coding.


If I understand the question, you don't want ctime or any of its kin. As I
understand it you are writing a simulator, so the program *simulates* the
passing of time. ctime has to do with real time in the real world, not
simulated time in a simulated world. A simulation program creates and
controls its own time and advances it if, as and when it thinks necessary.
Like so:

double timex = 0.0; // Because the identifier "time" may be already used
by the system.

An advance of 1.0 might mean one picosecond or one year. It's up to you,
you own it.
Jul 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.