ctime Help

Discussion in 'C++' started by Kevin, May 16, 2004.

  1. Kevin

    Kevin Guest

    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
    Kevin, May 16, 2004
    #1
    1. Advertising

  2. Kevin

    Leor Zolman Guest

    On 15 May 2004 18:48:17 -0700, (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
    Leor Zolman, May 16, 2004
    #2
    1. Advertising

  3. Kevin

    Ian Guest

    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
    Ian, May 16, 2004
    #3
  4. Kevin

    osmium Guest

    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.
    osmium, May 16, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ernst Murnleitner

    replacement for <ctime>?

    Ernst Murnleitner, Jul 16, 2003, in forum: C++
    Replies:
    8
    Views:
    529
    Limech
    Jul 20, 2003
  2. Tivo Escobar

    Question about ctime

    Tivo Escobar, Jul 23, 2003, in forum: C++
    Replies:
    1
    Views:
    389
    Victor Bazarov
    Jul 23, 2003
  3. Oplec
    Replies:
    2
    Views:
    493
    Oplec
    Oct 26, 2003
  4. wukexin
    Replies:
    1
    Views:
    467
    Karl Heinz Buchegger
    May 25, 2005
  5. B Williams

    Help with C++ <ctime>

    B Williams, Jul 10, 2006, in forum: C++
    Replies:
    8
    Views:
    3,655
    Ron Natalie
    Jul 10, 2006
Loading...

Share This Page