• Advertisement

Archived

This topic is now archived and is closed to further replies.

How do I make a "timer"(I'm a beginner)

This topic is 6525 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How do I make a timet that count the amount of milliseconds that have passed since the timer has started. example: timer start do lots of stuff print "how much time has gone"

Share this post


Link to post
Share on other sites
Advertisement
If you''re using Windows, you can call the WIN32 API function GetTickCount() to get the amount of milliseconds from Windows start in the beginning into some variable, do the "stuff", then call it again and substract the old tick count from the new tick count.

Share this post


Link to post
Share on other sites
Windows has a millisecond multimedia timer,
If u include ''winmm.lib'' you have access to the function:-

DWORD timeGetTime();

which reurns the time elapsed since windows was started, and as long as u''r app doesn''t run any longer than 49.71 days constantly then u''ll be fine.(if it does for some reason go over this u would have to use the difference between twot values - but I doubt windows can run for 49 days without crashing)

Now for u''r specific case u simply need to have to variables, and compare the two, i.e:-

double start,end,elapsed;
start = timeGetTime();

//Do other stuff....

end = timeGetTime();
elapsed = end-start;

cout << "time elapsed: " << elapsed;

This could be simplified to elapsed = start-timeGetTime(); and leave out the end variable.
I hope thats helped, if theres any errors feel free to complain

____________________________________________________________
Hey I knew the answer thats a first.

Seaman.

Share this post


Link to post
Share on other sites

  • Advertisement