Fast, cross-platform timer?

Posted by dsimcha on Stack Overflow See other posts from Stack Overflow or by dsimcha
Published on 2011-02-21T23:20:51Z Indexed on 2011/02/21 23:25 UTC
Read the original article Hit count: 163

Filed under:
|
|
|

I'm looking to improve the D garbage collector by adding some heuristics to avoid garbage collection runs that are unlikely to result in significant freeing. One heuristic I'd like to add is that GC should not be run more than once per X amount of time (maybe once per second or so). To do this I need a timer with the following properties:

  1. It must be able to grab the correct time with minimal overhead. Calling core.stdc.time takes an amount of time roughly equivalent to a small memory allocation, so it's not a good option.

  2. Ideally, should be cross-platform (both OS and CPU), for maintenance simplicity.

  3. Super high resolution isn't terribly important. If the times are accurate to maybe 1/4 of a second, that's good enough.

  4. Must work in a multithreaded/multi-CPU context. The x86 rdtsc instruction won't work.

© Stack Overflow or respective owner

Related posts about time

Related posts about garbage-collection