1

Possible Duplicate:
High resolution timer with C++ and Linux?

double hires_time_in_seconds();

I'm looking for this function for Windows, Linux too if you have it. It is mentioned in http://gafferongames.com/game-physics/fix-your-timestep/. I've looked on the web. I know it's not a standard function but if anybody has an implementation that they want to share, that would be great.

Failing that, I need something as fine grained as possible to do synchronization in a client server game.

Community
  • 1
  • 1
ScrollerBlaster
  • 1,578
  • 2
  • 17
  • 21
  • Have you looked at [Boost.DateTime](http://www.boost.org/libs/date_time/)..? It provides microsecond or nanosecond resolution, depending on how you build. (Also, how is a timer with seconds-level granularity "hires"?) – ildjarn Jan 09 '12 at 21:20
  • You should refer to http://stackoverflow.com/questions/275004/c-timer-function-to-provide-time-in-nano-seconds. – Volodymyr Rudyi Jan 09 '12 at 21:22
  • C++ has `std::chrono::high_resolution_clock` now. It hasn't been implemented in VS as of VS2010, but GCC on linux should have it. – bames53 Jan 09 '12 at 21:28
  • @bames53 : Good point, and for older platforms there is now [Boost.Chrono](http://www.boost.org/libs/chrono/). – ildjarn Jan 09 '12 at 21:29
  • Rather than Boost I'll probably use the Windows and Unix specific versions mentioned in the duplicates. Cheers. – ScrollerBlaster Jan 09 '12 at 21:35

1 Answers1

4

It's not a real function, it's just a self-descriptive placeholder name used in that blog post's example code.

For Windows, you'll want to use QueryPerformanceCounter along with QueryPerformanceFrequency. For Unix-based OSes, you'll want to use gettimeofday(3).

Adam Rosenfield
  • 390,455
  • 97
  • 512
  • 589