Time Function

This is a discussion on Time Function within the C++ Programming forums, part of the General Programming Boards category; Hey everyone, I'm in Algorithms and Data Structures at Syracuse University, and for one of the homeworks I finished most ...

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    2

    Time Function

    Hey everyone,
    I'm in Algorithms and Data Structures at Syracuse University, and for one of the homeworks I finished most of the code, which is supposed to read a text file and convert it into strings to input into a linked list. However, we are supposed to have a timer that times how long it takes to compile all of the strings from the text file. I am currently using the time.h function, but it is not accurate enough, as I need it to be able to measure to milliseconds. Anyone know a good function or piece of code to use to have this work? I would appreciate it greatly if someone is able to help me on this. If I'm not clear enough, just tell me and I'll send you some more info.

  2. #2
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    You can use timeGetTime(). It measures in milleseconds. You'll need to include <mmsystem.h> and link winmm.lib. A basic exmample would be like this:

    Code:
    DWORD dwStart=timeGetTime();
    //do your stuff to time here
    DWORD dwEnd=timeGetTime();
    DWORD dwElapsed=dwEnd-dwStart;

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    One option is to use the clock() function.
    Code:
       clock_t start, finish;
       double time_elap;
    
       start = clock();
    .
    .
    .
       finish = clock();
    
       time_elap = (finish-start)/CLK_TCK;  //or CLOCKS_PER_SEC
       cout << "time elapsed:" << time_elap << " sec" << endl;
    Or there's also function ftime() which has millisec in <sys\timeb.h>

  4. #4
    Registered User
    Join Date
    May 2002
    Posts
    2
    I got it to work, thanks a lot guys! This thing was due by midnight, so i got a few hours to spare!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  2. Sending an email in C program
    By Moony in forum C Programming
    Replies: 28
    Last Post: 10-19-2006, 10:42 AM
  3. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  4. Replies: 5
    Last Post: 02-08-2003, 06:42 PM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21