Measuring CPU Superscalar factor with noploop.c

While reading The noploop CPU Benchmark I decided to do a small experiment to calculate the CPU Superscalar factor, this consists in measuring the number of instructions that the CPU completes by cycle. That can be accomplished measuring the number of CPU cycles it takes to perform a fixed amount of NOPs (NO Operation) instructions, as shown below:

start = cpucycles()
perform 4096 * 100000000 NOPs
end   = cpucycles()

Superscalar CPU factor = (4096 * 10000000) / (end - start)

To measure the superscalar factor, we can write a small self-contained program (sources here: noploop.c) based on the above pseudo-code, that calculates the CPU frequency and the CPU superscalar factor:

box $ ./noploop
noploop: freq 14321678 KHz (time 2860 ms) 3325978 KHz (9512297394 cycles)
noploop: CPU Superscalar factor: 4 instr/cycle

box $ grep name /proc/cpuinfo
model name : Intel(R) Core(TM) i5-2500K CPU @ 3.30GHz

The above results shows that the CPU took 2860 milliseconds and 9512297394 CPU cycles to perform the 4096 10^7 NOP instructions. This gives the following figures:

  • a rate of 14321678 KHz instructions completed per second, obtained with rate = NOPs / time
  • a frequency of 3325978 KHz CPU cycles per second, obtained with freq = cycles / time

The difference between the rate of 14.32 GHz instructions completed per second and the 3.30 GHz CPU cycles/second means that the CPU is completing 4 NOP instructions/cycle, that is the CPU Superscalar factor.