Fast, cross-platform timer?
- by dsimcha
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:
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.
Ideally, should be cross-platform (both OS and CPU), for maintenance simplicity.
Super high resolution isn't terribly important. If the times are accurate to maybe 1/4 of a second, that's good enough.
Must work in a multithreaded/multi-CPU context. The x86 rdtsc instruction won't work.