#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2003
    Posts
    9
    Rep Power
    0

    Question How can I make my timer more precise in C++?


    I've been working on a timing code and everything is working fine except that i need to make it more precise.

    Here is a piece of my code:

    time_t startname1, endname1;
    cin ch;
    if (ch == 'a')
    {
    startname1 = time(NULL);
    }
    cin ch;
    if (ch == 'a')
    {
    endname1 = time(NULL);
    }

    printf("Total time: %ld seconds\n",(long) (endname1-startname1));




    It works but it displays something like 10 seconds and I want to know if there is a way to display the tenths of a second, or even the hundredth of a second (eg. 10.15 seconds)

    thanks
  2. #2
  3. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95
    look up the getimeofday() function. it is microsecond resolution.

IMN logo majestic logo threadwatch logo seochat tools logo