Fast timer, NOT win32

Started by
10 comments, last by dusik 22 years, 2 months ago
I am programming a 3D engine to support multiple OS''s. So, for Win32 I can use timeGetTime(), etc. But what would I use in Linux? clock() is waaaay too slow! Completely stumped. I''d be very greatful for some info on this. Thanks
------------------------CRAZY_DUSIK* pCrazyDuSiK = new CRAZY_DUSIK;pCrazyDuSiK->EatMicroshaft(MS_MUNCH_BILL_GATES | MS_CHEW_BILL_GATES);pCrazyDuSiK->WebSiteURL = "http://www.geocities.com/dusik2000";
Advertisement
An assembly language routine.
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
So ASM is the only way? OK I suppose I could handle that. Strange though that there''s not a nice standard C func for that....

Thanks a lot
------------------------CRAZY_DUSIK* pCrazyDuSiK = new CRAZY_DUSIK;pCrazyDuSiK->EatMicroshaft(MS_MUNCH_BILL_GATES | MS_CHEW_BILL_GATES);pCrazyDuSiK->WebSiteURL = "http://www.geocities.com/dusik2000";
Have you had a look what's in the Linux time.h header? Some of the functions there might be of use to you.

--
Very simple ideas lie within the reach only of complex minds.

Edited by - SabreMan on February 17, 2002 9:22:47 AM
How about clock() function in time.h ?
I wish.... clock() is way too inaccurate. I need accuracy to at least 1 millisecond.
------------------------CRAZY_DUSIK* pCrazyDuSiK = new CRAZY_DUSIK;pCrazyDuSiK->EatMicroshaft(MS_MUNCH_BILL_GATES | MS_CHEW_BILL_GATES);pCrazyDuSiK->WebSiteURL = "http://www.geocities.com/dusik2000";
Why, is the time.h header different for Linux than for Windows? I thought it was a standard C header.
------------------------CRAZY_DUSIK* pCrazyDuSiK = new CRAZY_DUSIK;pCrazyDuSiK->EatMicroshaft(MS_MUNCH_BILL_GATES | MS_CHEW_BILL_GATES);pCrazyDuSiK->WebSiteURL = "http://www.geocities.com/dusik2000";
quote:Original post by dusik
Why, is the time.h header different for Linux than for Windows? I thought it was a standard C header.


Whoops, yes. I was working from memory which often isn''t the most accurate of techniques. Especially when I haven''t used the header in question for over a year!

--
Very simple ideas lie within the reach only of complex minds.
i would create a simple function, inline probably. along the lines of this:
  int checktimer(long timer) {   if (timer <= time()) {      return 1;   }   return 0;}  

then you would use it by first creating a timer variable and then calling the checktimer() to see if the timer had occured:
  long timer = time() + 1000; // set a timer for in a secondwhile (checktimer(timer) == 0) { }printf("Second is over.\n");  


(http://www.ironfroggy.com/)
(http://www.ironfroggy.com/pinch)
(http://www.ironfroggy.com/)(http://www.ironfroggy.com/pinch)
I still don''t see, though, how this would allow me to calculate, say, frames per second. Say, I''ve got 100 FPS. That means, each frame takes 10 milliseconds to render. So I would do something like:

  void TimerTick(){ static long prevtime = time(); long currtime = time(); g_FPS = (1.0f / (float)(currtime-prevtime)); prevtime = currtime;}  


That is similar to what I''ve got now (though simplified) but instead of time() I use timeGetTime() using the Win32 API. The reason is, timeGetTime is accurate to 1 millisecon, which is what I need, whereas the functions in (clock(), time()) are way too inaccurate.

Also, if I''m not mistaken, ironfroggy, the code you wrote is a delay, not a measure of time. I need to measure how much time the frame has been rendering, not pause the programme for any amount of time.

But thanks anyway.
------------------------CRAZY_DUSIK* pCrazyDuSiK = new CRAZY_DUSIK;pCrazyDuSiK->EatMicroshaft(MS_MUNCH_BILL_GATES | MS_CHEW_BILL_GATES);pCrazyDuSiK->WebSiteURL = "http://www.geocities.com/dusik2000";

This topic is closed to new replies.

Advertisement