0

Does boost chrono provides time stamp with nanoseconds resolution?? If yes how to get the time stamp?

Narek
  • 38,779
  • 79
  • 233
  • 389
  • As you insist. The best you can theoretically get since Vista is by using HPET (High Precision Event Timer). See here http://en.wikipedia.org/wiki/High_Precision_Event_Timer. The problem is how to get it via QueryPerformanceCounter() that uses the HPET when available and set in BIOS. – SChepurin Oct 18 '12 at 15:15
  • @SChepurin "The best you can theoretically get since Vista is by using HPET"? Why if my processor works with 3.33 GHz it is because it is the fastes clock in OS? – Narek Oct 19 '12 at 08:40

2 Answers2

2

Nanoseconds resolution ? On which hardware do you want to run your program ? On my PC, my performance counter has a frequency of approx. 4 Mhz, so a tick last 250 ns.

As answered here, boost chrono can give you the nanosecond resolution, but you will not be sure of the measure's accuracy.

Community
  • 1
  • 1
lucasg
  • 10,734
  • 4
  • 35
  • 57
  • So how to know my performance counter frequency? And is this the only criterion that indicates the precision? – Narek Oct 18 '12 at 18:11
  • as stated by @SChepurin, QueryPerformanceFrequency() retrieve your HPET's frequency clock (in Hz) if you work on Windows. For Linux, there should be a equivalent function, but I do not know its name. For more info : http://www.mindcontrol.org/~hplus/pc-timers.html – lucasg Oct 18 '12 at 19:47
  • I mean if you processor is 3.33GHz it is not enough to obtain time in nanoseconds? Why would we concern about HPET's frequency? – Narek Oct 19 '12 at 08:35
  • you can use CPU time ( a lot of methods are posted [here](http://stackoverflow.com/questions/275004/c-timer-function-to-provide-time-in-nano-seconds) ) but remember that we don't know the accuracy of the CPU's clock frequency (is it 3.33Ghz or 3.00 Ghz ?) nor the CPU's optimization ( wall time, load balancer if several cores, ...). I think the result given by CPU time measurement does not have any significant figures below the microsecond. – lucasg Oct 19 '12 at 09:08
1

In order to easily get time stamps with boost chrono for different measurements you can use boost CPU Timers. A table about the timer accuracy is also given on this site.

To measure the resolution yourself on your specific hardware use boost's cpu_timer_info.cpp.

spinxz
  • 401
  • 3
  • 13