sparkx 0 Report post Posted January 2, 2009 How do I get the current time (in milliseconds or better) using C++? I need to find the difference between two intervals in time so my program can adjust so it won’t be real fast on some computer and real slow on others.I have tried time() from ctime.h. It turns out that it is not accurate at all (as it seems to round to the nearest second, which is not good enough for my program).I have also tried clock() then dividing by CLOCKS_PER_SEC but doing this worries me because it is a macro and is getting the CLOCKS_PER_SEC of the computer that compiled the program, not the one that is running it.Is there another option that works better?Thanks,Sparkx Share this post Link to post Share on other sites
Quatrux 4 Report post Posted January 3, 2009 I think you can try to search google, but I didn't do much of C++ and didn't test this, but if on Windows OS, you can use timeGetTime(); I guess..you need to include as I remember <windows.h> or something like that and use timeGetTime(); which will return time in milliseconds. I think it's very usable using C++ and DirectX on Windows, on a simple console applications I never really used any functions to get time. Share this post Link to post Share on other sites
Lordrach 0 Report post Posted January 4, 2009 hi,I suggest you to use the free and open source SDL library, i have used it for 2d game programming and i can say it's really a nice API (2D, images, networking, Audio, fonts).for time management you can use the SDL_GetTicks function witch returns the number of milliseconds since SDL library initialization. the SDL library offers another way to managing time witch is the timers.you can find more information about time management in SDL here Share this post Link to post Share on other sites
sparkx 0 Report post Posted January 5, 2009 Thanks for the replies, I think timeGetTime() is the one I am looking for. By the way I was wondering, is there a way to debug a program to see how long each thing takes to execute. Before I was just using the sleep() function to update the time every 10 milliseconds then calling the time throughout the rest of the program (which works for development but I'm not sure how it works for releases). This seems like it should work better then anything else unless the total execution time is significantly larger then 10 milliseconds (of coarse it should be a little longer then 10 milliseconds because of the sleep and execution but that is why I am using intervals of 10 not 1 keeping my program more accurate). Is it method valid?Thanks,Sparkx Share this post Link to post Share on other sites