Results 1 to 2 of 2

Thread: elapsed time?

  1. #1

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    Does any one knoe how i can calculate elapsed time?

    This is the crap that microsoft has included in their
    MSDN Library:

    CTime startTime = CTime::GetCurrentTime();

    // ... perform time-consuming task ...

    CTime endTime = CTime::GetCurrentTime();

    CTimeSpan elapsedTime = endTime - startTime;

    They say that you have to include #include <afx.h>.
    So are Ctime & CTimeSpan, classes that are already defined
    in the afx header file? Im trying to calculate feet travled
    based on current speed. but i have no clue how to do this.

    do while(cur_speed > 0)
    {
    feet_travled = cur_speed * seconds() * 1.46;
    }

    thanks

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    don't use the afx functions for this...

    Code:
    #include <time.h>
    
    void myfunc() {
        time_t start;
        time_t end;
        time_t elapsed;
        float speed, distance;
    
        start = time();
    
        // task here
    
        end = time();
        elapsed = (end - start);
    
        // elapsed is now in clock units (usually ms)
    
        elapsed /= CLOCKS_PER_SEC;
    
        // elapsed is in seconds
    
        speed = distance / elapsed;
    }
    the time.h header is standard and will work whatever. (I'm assuming SI units for calculations). CTime and CTimeSpan are MFC classes.

    to use something useful, you need to do something like keep track of the time, then every 2 seconds, find the distance travelled in the past 2 secs to find the speed. you can't really work out the time over 0 secs because you'd have to differentiate (nasty).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width