0

Following the question CLOCKS_PER_SEC not actually clocks per sec, the same code on my multicore machine gives:

CLOCKS_PER_SEC = 1000000
Actual clocks per second = 89815
Actual clocks per second = 999801
Actual clocks per second = 998912
Actual clocks per second = 999911
Actual clocks per second = 1000019
Actual clocks per second = 999997
Actual clocks per second = 1000194
Actual clocks per second = 1000182
Actual clocks per second = 1000216
Actual clocks per second = 999990

Why is the actual clocks/sec greater than 1,000,000 in a few cases? Due to the multicore? How do we explain this?

I am running a Linux kernel 4.0.4-202 Fedora 21 on hardware Architecture: x86_64 CPU(s): 8 On-line CPU(s) list: 0-7 Thread(s) per core: 2 Model name: Intel(R) Core(TM) i7-4910MQ CPU @ 2.90GHz CPU MHz: 967.195 CPU max MHz: 3900.0000 CPU min MHz: 800.0000

Community
  • 1
  • 1
hAcKnRoCk
  • 1,118
  • 3
  • 16
  • 30

1 Answers1

0

On a busy system, the running test program isn't going to be granted all CPU power.

There is then no guarantee for it not to be suspended for some period of time. If the turnover from one second to the next happen when the process is waiting for a CPU, the next clock() call will happen late, thus the "more than one second" delta.

Alternatively, the variation you see might be due to some rounding happening in the clock() call.

In any case, I do not reproduce it on various systems, either single or multi-core.

jlliagre
  • 29,783
  • 6
  • 61
  • 72