I am timing multiple NOP instructions and a single NOP instruction in C++, using rdtsc. However, I don't get an increase in the number of cycles it takes to execute NOPs in proportion to the number of NOPs executed. I'm confused as to why this is the case. My CPU is Intel Core i7-5600U @ 2.60Ghz.
Here's the code:
#include <stdio.h>
int main() {
unsigned long long t;
t = __rdtsc();
asm volatile("nop");
t = __rdtsc() - t;
printf("rdtsc for one NOP: %llu\n", t);
t = __rdtsc();
asm volatile("nop; nop; nop; nop; nop; nop; nop;");
t = __rdtsc() - t;
printf("rdtsc for seven NOPs: %llu\n", t);
}
I am getting values like:
rdtsc for one NOP: 78
rdtsc for seven NOPs: 91
rdtsc for one NOP: 78
rdtsc for seven NOPs: 78
when running without setting processor affinity.
When setting processor affinity like $ taskset -c 0 ./nop$, the results are:
rdtsc for one NOP: 78
rdtsc for seven NOPs: 78
rdtsc for one NOP: 130
rdtsc for seven NOPs: 169
rdtsc for one NOP: 78
rdtsc for seven NOPs: 143
Why would this be the case?