1

I am trying to see how many cycles does 1 nanosecond takes on my laptop.

Laptop Config :

  1. Processor : Intel Centrino Duo 2.0 GHz ( T7200 )
  2. Memory : 2 GB

Following are the counts :

  1. 1 second takes : 1995198000 ( which is close to 2 billion ticks, which is OK )
  2. 1 milli second : 2,159,460 ( close to 2 Million , which is OK)
  3. 1 micro second : 507,408 ( Why ? )
  4. 1 nano second : 139,000 ( Why ? )

Till 1 micro seconds the ticks are in accordance with Frequency. However, below that, it is not. Also, I can differentiate between 100 nsec and 200 nsec using the cycle counts reliably, not below that.

Setup to measure :

  1. Measuring process is attached to one processor.
  2. Priority of process is set to highest.
  3. CPU is set to run at highest frequency all the time.

Can anyone explain the reason ? Is it because of the sleep ( I am using nanosleep) being implemented in such way. ?

dudedev
  • 451
  • 1
  • 5
  • 19

2 Answers2

1

From the specification of nanosleep:

The suspension time may be longer than requested because the argument value is rounded up to an integer multiple of the sleep resolution or because of the scheduling of other activity by the system.

Klas Lindbäck
  • 33,105
  • 5
  • 57
  • 82
1

The closest you'll get using PC hardware is using statistical analysis of longer time durations. It takes more than a nanosecond to measure time using RDTSC: ZeroMQ Test Analysis

user1016736
  • 390
  • 4
  • 7
  • I understand that there is an overhead. Negating the overhead should work .. right? I calculate the overhead by making three calls to RDTSC as explained [here](https://www.ccsl.carleton.ca/~jamuir/rdtscpm1.pdf) I also use cpuid instruction to serialize. – dudedev Nov 10 '14 at 13:21