1

The new clocks in the std namespace all appear to be statically instantiated. high_resolution_clock is not a class of clocks with high resolution, but rather the system-wide high resolution clock, with static methods such as now.

I understand why they did it this way, but I have use for instanced clocks. In my case, I am emulating the presence of N high resolution clocks, one on each emulated board in an emulated device, where N is decided at runtime. In addition, the clock periods are decided at runtime.

My needs are clearly not identical to what the C++11 clocks offer. Is there a common approach to reusing the official classes like time_point<Clock, Duration> referencing a runtime instance of a clock? I may end up needing to rewrite the entire clock API to suit my needs, but I'd love to reuse the standard work to save time.

Cort Ammon
  • 10,221
  • 31
  • 45
  • If the clocks are all accurate, wouldn't they be the system clocks plus or minus an offset? Otherwise, you’d need some transformation of the system time to the simulated time, *e.g.* `t + (t%(15U*60U*CLOCKS_PER_SEC))*23/20` if the simulated clock should run 15% too fast and get corrected every 15 minutes. – Davislor Oct 07 '15 at 19:51
  • In the real hardware, there will be a small delta between the clocks, as is natural for clock jitter, which matters for this hardware application. If, in simulation, they were to use the same clock, there would be no delta, so thus I would not be testing whether the algorithms are resilient to such jitter. There will, of course, be some simulation based transform like you describe in the end, but I'm trying to keep that effect isolated from the algorithms under test. – Cort Ammon Oct 07 '15 at 19:55
  • Maybe add some noise? – Davislor Oct 07 '15 at 20:24
  • @Lorehead That's my plan. The question is where, and whether I can use the standard durations and time_points, or if I have to write my own to account for the need to have a runtime-specified number of noisy clocks. – Cort Ammon Oct 07 '15 at 20:45
  • You should be able to use *has-a* inheritance and duck-type the methods. – Davislor Oct 07 '15 at 21:01

0 Answers0