Skip to content
Tactiverge

Computer architecture

Clock speed, cycles and CPI

Also called: clock frequency · CPI · cycles per instruction · execution time · MHz

Definition

Execution time equals the number of instructions times the average cycles per instruction (CPI) divided by the clock frequency.

Picture it

A faster clock is only one of three levers: you can also run fewer instructions (better algorithm or compiler) or need fewer cycles per instruction (better design). Comparing processors by MHz alone ignores the other two.

The maths

t = N_instr × CPI / f_clock
clock period T = 1 / f
SI units used in this entry
QuantityUnitSymbol
timeseconds
frequencyhertzHz
clock cyclescycle (count)1

Worked example

A control routine executes 48000 instructions with an average CPI of 1.5 on a 72 MHz microcontroller. How long does it take, and can it run inside a 1 kHz loop?

  1. Cycles = 48000 × 1.5 = 72000
  2. t = 72000 / 72 000 000 = 0.001 s = 1 ms
  3. A 1 kHz loop has exactly 1 ms per pass: no time left for anything else

Answer1 ms: it would use the entire 1 kHz loop budget.

✓ The number in this answer is recomputed from scratch by an automated test.

Common misconceptions

  • Misconception: Doubling the clock does not halve the time if memory stalls dominate.
  • Misconception: CPI is an average for a particular program, not a fixed property of the chip.