LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   timing in c++ (https://www.linuxquestions.org/questions/programming-9/timing-in-c-172548/)

deveraux83 04-20-2004 01:17 PM

timing in c++
 
Hi all,

Was just wondering the best method to keep track of time elapsed or just real time for that matter. I know that in glX code, you get use the function getMilliSeconds() to return time elapsed in milli seconds while in SDL you can use SDL_GetTicks() to do the same thing. However, is there a way of doing it in console mode?

I've tried reading some stuff on time/date in c++ but can't seem to figure it out (ie localtime/gmtime require a time argument). Any help/suggestions?

Thanks

jim mcnamara 04-20-2004 01:38 PM

If I get what you want: gettimeofday() returns a very fine grained time.
It's in time.h

The_Nerd 04-20-2004 05:34 PM

Time.h
 
Code:

#include <stdio.h>
#include <time.h>

int main(int argc, char **argv)
{
        clock_t startTime=0;

        while(1)
        {
                startTime=clock();
                while((clock()-startTime)/CLOCKS_PER_SEC<1000); //Sleep one second
                printf("One second elapsed!");
        }   
}

Now I don't know if thats perfect, because its off the top of my head. But I do know you need to look into clock() from time.h

Enjoy!


All times are GMT -5. The time now is 04:15 PM.