Skip to content
BetterDL

CPU execution time

Also called: execution time, CPU time, performance equation, iron law of performance

How long a program takes to run: instructions executed × CPI × clock period, or equivalently instructions × CPI ÷ clock frequency.

The CPU execution time of a program is given by one equation:

time = instructions × CPI × clock period

or, the same thing, instructions × CPI ÷ frequency.

Read it in two parts: instructions × CPI is the total number of clock cycles; multiplying by the clock period turns cycles into seconds.

So there are exactly three ways to make a program faster:

  • execute fewer instructions (a better algorithm or a richer instruction set);
  • need fewer cycles per instruction (better control or more parallel hardware);
  • use a shorter clock period (faster circuits or more pipelining).

They often trade against each other. A single cycle processor has CPI = 1 but a long period; a multi cycle processor has a short period but CPI > 1. Only the full product says which wins.

Write units next to every number. Most slips are a lost factor of 1000 between ns, µs and ms.

Worked examples

Example

Timing a program

A program executes 2 000 000 instructions with CPI 3 on a 250 MHz clock.

  1. 1.

    Period: 1000 ÷ 250 = 4 ns.

  2. 2.

    Cycles: 2 × 10⁶ × 3 = 6 × 10⁶.

  3. 3.

    Time: 6 × 10⁶ × 4 ns = 24 × 10⁶ ns.

  4. 4.

    Convert: 24 × 10⁶ ns = 24 000 µs = 24 ms.

Example

Which CPU is faster?

CPU A: 2 GHz, CPI 2.0. CPU B: 1.5 GHz, CPI 1.2. Both run the same 10⁹ instructions.

  1. 1.

    A: 10⁹ × 2.0 ÷ (2 × 10⁹) = 1.0 s.

  2. 2.

    B: 10⁹ × 1.2 ÷ (1.5 × 10⁹) = 0.8 s.

  3. 3.

    B is faster, by 1.0 ÷ 0.8 = 1.25 times, despite its slower clock.

Common mistakes

  • Stopping at cycles. A cycle count isn't a time until you multiply by the period.

  • Multiplying by the frequency, which gives a 'time' that grows as the clock gets faster.

  • Losing a factor of 1000 between ns, µs and ms.

Practice CPU execution time

Interactive questions with instant feedback and a worked solution for every wrong answer.

Learn it step by step

CPU execution time is taught in Basic CPU / Computer Architecture.