Cycles per instruction (source code)

= Cycles per instruction
{title2=$\mathrm{CPI}=C/N$}

<Cycles per instruction> is the average number of processor clock cycles spent per counted <machine instruction>[instruction] for a specified execution interval and counting convention. If $N$ <machine instructions>[instructions] complete in $C$ cycles, $\mathrm{CPI}=C/N$. At constant <clock frequency> $f$, execution time satisfies
$$
T=\frac{N\,\mathrm{CPI}}{f}.
$$
For example, $10^9$ completed <machine instructions>[instructions] at CPI 1.5 and $3\times10^9$ <hertz> take 0.5 <seconds>.

The value depends on <machine instruction>[instruction] mix, dependencies, <cache miss>[cache misses], branch behavior and the chosen <microarchitecture>. It can be less than one when several <machine instructions>[instructions] complete per cycle. A long-latency <machine instruction>[instruction] need not prevent other independent work from overlapping, so individual <machine instruction>[instruction] latencies cannot simply be added to predict elapsed time. Comparing processors by <frequency> alone ignores both CPI and the number of <machine instructions>[instructions] needed for the same task.