ctime Help

K

Kevin

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
 
L

Leor Zolman

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
 
I

Ian

Kevin said:
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
 
O

osmium

Kevin said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top