Lite / Textbooks / Computer Architecture / Chapter 2
2. The performance equation
Introduction
Execution time is instructions × cycles per instruction × seconds per cycle. That one line, the Iron Law, keeps every performance argument honest. A faster clock means little if each instruction needs more cycles; a clever instruction means little if the clock must slow to fit it. This chapter finds the clock period from the critical path, compares single-cycle and multi-cycle datapaths, and budgets cycles for a real-time signal loop.
Figure 2.1. The clock is not the whole story (described in words)
Two designs run the same one billion instructions. Design A has CPI 1.2 at 2.5 GHz and takes 0.48 s. Design B has a lower CPI of 0.9 but a slower 1.8 GHz clock and takes 0.5 s. Neither the clock rate nor the CPI alone decides which is faster.
Explanation
Built from 4 School lessons. Each part is the lesson's own explanation.
2.1 How fast can the clock tick?
Why can't a processor designer just set the clock to 100 GHz and make everything 25 times faster?
The critical path
Every path from a register output through gates to a register input must settle within one clock period. The longest one sets the clock. In a ripple-carry adder it is the carry rippling through every column: about 2 gate delays per bit, so a 32-bit ripple adder is roughly eight times slower than a 4-bit one.
Shortening it
Designers attack the critical path with faster circuits (carry-lookahead adders compute carries in parallel at the cost of more gates), or by pipelining: putting registers in the middle of a long path so each piece fits a shorter period. The clock speeds up; each operation now takes more cycles, but a new one can start every cycle.
More cycles or faster cycles?
Run time = cycles × T_clk. A single-cycle design does everything in one long cycle; a multi-cycle design (like the 3-step model in the stepper) uses several short ones. Which wins depends on how evenly the work splits: the iron law T = IC × CPI × T_clk keeps every trade-off honest.
Derivation: The register-to-register timing constraint
At a clock edge the launching register's output changes after t_clk→Q.
The new value travels through combinational logic; the slowest route, the critical path, takes t_logic.
The capturing register needs its input stable for t_setup before the next edge.
So the next edge must come no sooner than T_clk ≥ t_clk→Q + t_logic + t_setup, and f_max = 1/T_clk.
Example: 0.2 + 10 × 0.1 + 0.1 = 1.3 ns, so f_max = 1/1.3 ns ≈ 769 MHz.
Common mix-ups
A faster clock always means a faster program.
✓ If faster clocks need more cycles per operation, run time = cycles × period may not improve.
Open the Lite lesson: How fast can the clock tick?
2.2 Single-cycle, multi-cycle and the Iron Law
Chip A runs at 4 GHz, chip B at 2 GHz. B finishes your program first. How?
Single-cycle datapath
Every instruction completes in one long clock cycle, so CPI = 1, but the cycle must be long enough for the slowest path (instruction memory → register read → ALU → data memory → register write, for a load). Simple instructions waste most of the cycle.
Multi-cycle datapath
Break execution into steps (fetch, decode, execute, memory, write-back) and give each step one short cycle. Instructions use only the steps they need, so CPI is now an average (perhaps 4) but the cycle is about the length of one step. Hardware can be reused across steps: one memory and one ALU instead of separate ones.
Three factors, coupled
A richer instruction set lowers IC but may raise CPI or the cycle time. A deeper pipeline shortens the cycle but raises CPI when hazards hit. A good comparison quotes all three and measures them on the same program, compiled the same way, which is why benchmark suites exist.
Derivation: The Iron Law, from units
Time per program = (instructions / program) × (cycles / instruction) × (seconds / cycle).
The units cancel: instructions × cycles/instruction × seconds/cycle = seconds. So T = IC × CPI × t_clk = IC × CPI / f.
IC is set by the algorithm, the compiler and the instruction set. CPI by the microarchitecture (pipelining, caches, prediction). t_clk by the circuit and the process technology.
Speed-up of B over A = T_A / T_B = (IC_A/IC_B) × (CPI_A/CPI_B) × (f_B/f_A).
Example: A has IC = 10⁹, CPI = 2, 4 GHz: T = 0.5 s. B has IC = 0.8×10⁹, CPI = 1.1, 2 GHz: T = 0.44 s. B wins by 0.5/0.44 ≈ 1.14× despite half the clock.
Common mix-ups
A higher clock frequency always means a faster computer.
✓ Only if IC and CPI stay the same. Execution time on the real workload is the only fair measure.Multi-cycle machines are slower because CPI > 1.
✓ Their cycle is much shorter, so time per instruction can be lower; CPI alone says nothing.
Open the Lite lesson: Single-cycle, multi-cycle and the Iron Law
2.3 Signals meet hardware: the cycle budget
A 48 MHz microcontroller sounds fast. Can it filter a 48 kHz audio signal in real time? It depends on one division.
The pipeline
Sensor → analog anti-aliasing filter → ADC (sample rate fs, N bits) → digital filter → decision or output. Each stage has a requirement from this term: fs > 2 × the highest wanted frequency with margin; N bits for the SNR you need; a filter whose response keeps the band and rejects noise; and a processor that keeps up.
The cycle budget
Cycles available per sample = f_clk / fs. Processor load = fs × (cycles per sample) / f_clk. Keep it well under 100 %, because interrupts, communication and the rest of the program need cycles too. A first-order IIR needs about two multiplies and an add per sample; an M-point moving average can be done with a running sum in constant time.
Trading between stages
A better analog filter lets you sample more slowly, saving cycles. More bits cost ADC time and memory but not filter cycles. An IIR filter gives strong smoothing for a handful of cycles but with phase lag; a long FIR filter has linear phase but costs a multiply per tap. Systems engineering is choosing these together, not one at a time.
Common mix-ups
If the average load is under 100 %, the system is real-time.
✓ Real-time needs the worst case to fit in every sample period, with margin for everything else.
Open the Lite lesson: Signals meet hardware: the cycle budget
2.4 Time, memory, accuracy: pick your trade
Halve the step size and the answer gets better. Halve it again and it gets slower. When do you stop?
Order of accuracy
A method of order p has global error ≈ C·h^p. Halving h divides the error by 2^p and doubles the work. Plot error against h on log–log axes: the slope is p, which is a powerful check that your code is correct. Below some h, rounding error in each step starts to accumulate and the curve turns back up.
Growth rates
An O(n) algorithm on a million items does about a million operations; O(n log n) about twenty million; O(n²) a trillion. For small n, a simple O(n²) method may be faster and far easier to verify. Choose by the sizes you actually face, measured, and by the cost of getting it wrong.
Memory as a resource
Storing results can save time (a lookup table replaces a slow sin(x)) at the cost of memory, and the table's spacing sets its accuracy. A microcontroller with 32 KB of RAM can't hold a 64 K-entry table, so you interpolate a smaller one. This is time versus memory versus accuracy in one decision.
Fixed point: precision you can count
Fixed-point stores x as an integer X = round(x·2^f) with f fractional bits. Resolution is 2^−f; rounding error is at most half of that per operation. Q8 (f = 8) resolves 1/256 ≈ 0.0039. It is fast and predictable on chips without a floating-point unit, but you must check the range (overflow) and the accumulated rounding in long loops.
Common mix-ups
Smaller steps are always more accurate.
✓ Truncation error falls but rounding error grows with the number of steps; there is an optimum, and a cost.The algorithm with the best big-O is always the right choice.
✓ For the sizes you actually face, constant factors, memory and verifiability can matter more.
Open the Lite lesson: Time, memory, accuracy: pick your trade
Worked examples
How fast can the clock tick?: example 1
A 16-bit ripple adder has 2 gate delays per bit plus 1, at 0.08 ns each, between registers with t_cq = 0.15 ns and t_su = 0.1 ns. Find f_max.
Solution
Gate delays = 2 × 16 + 1 = 33; t_logic = 2.64 ns. T = 0.15 + 2.64 + 0.1 = 2.89 ns. f_max ≈ 346 MHz.
Single-cycle, multi-cycle and the Iron Law: example 1
A mix is 50% ALU (4 steps), 20% loads (5), 10% stores (4), 20% branches (3). Step time 200 ps. Compare with an 800 ps single-cycle design.
Solution
CPI = 0.5×4 + 0.2×5 + 0.1×4 + 0.2×3 = 4.0. Time per instruction = 4.0 × 200 ps = 800 ps: a tie. Shorten the step to 180 ps (balancing stages better) and multi-cycle wins: 720 ps.
Signals meet hardware: the cycle budget: example 1
An 80 MHz processor filters a 44.1 kHz signal with a 128-tap FIR at 3 cycles per tap plus 100 cycles of overhead. What is the load?
Solution
Cycles per sample = 128 × 3 + 100 = 484. Load = 44,100 × 484 / 80,000,000 ≈ 26.7 %.
Time, memory, accuracy: pick your trade: example 1
Euler gives error 0.32 at h = 0.4 and 0.16 at h = 0.2. Estimate p, then predict the error at h = 0.05.
Solution
p = log(0.32/0.16)/log(2) = 1. At h = 0.05 (8× smaller than 0.4) the error ≈ 0.32/8 = 0.04, for 8× the steps.
Laboratory
These run in a browser on the full site (they need a faster connection). Simulations are simplified educational models.
- Simulation OS: Adder architecture (Simulation OS experiment)
Compare ripple-carry and carry-lookahead adders at 8, 16 and 32 bits and say which one would set the clock period.
Open on the full site - Silicon Studio: Fetch, decode, execute (Silicon Studio stage)
Count the clock cycles each instruction takes and compute the average CPI of a short program.
Open on the full site
Practice
Each question links to its Lite lesson, where your answer is checked on our server and a wrong answer gets a hint. Answers are never sent to your device.
- What sets the maximum clock frequency of a synchronous design?
Answer it in “How fast can the clock tick?” - Adding a pipeline register halfway along the critical path usually…
Answer it in “How fast can the clock tick?” - A compiler optimisation removes redundant instructions without changing the hardware. Which Iron Law factor does it change most directly?
Answer it in “Single-cycle, multi-cycle and the Iron Law” - Design A: CPI 1.6 at 3 GHz. Design B: CPI 1.0 at 2.4 GHz, same instruction count. What is B's speed-up over A?
Answer it in “Single-cycle, multi-cycle and the Iron Law” - A 16 MHz microcontroller samples at 8 kHz. How many clock cycles are available per sample?
Answer it in “Signals meet hardware: the cycle budget” - A system is at 95 % load. Which change reduces load WITHOUT reducing the frequencies you can capture?
Answer it in “Signals meet hardware: the cycle budget” - A sensor value is stored in Q8 fixed point (8 fractional bits). What is the largest possible rounding error for one stored value?
Answer it in “Time, memory, accuracy: pick your trade” - You sort 40 sensor readings once per second on a microcontroller. Is a simple O(n²) insertion sort acceptable?
Answer it in “Time, memory, accuracy: pick your trade”
Engineering applications
Choosing a microcontroller
For a control loop at 8 kHz, divide the clock rate by the sample rate to get the cycle budget per sample. That number, not the clock rate on the box, says whether the filter will fit.
Compiler flags
An optimising compiler mostly cuts instruction count; some options trade more instructions for fewer stalls. The Iron Law explains why a 'bigger' program can run faster.
Watch (optional)
Streaming video uses a lot of data. Everything you need is in the text.
- “Advanced CPU Designs: Crash Course Computer Science #9” by CrashCourse
- “8-bit CPU control logic: Part 1” by Ben Eater
Summary
- CPU time = instruction count × CPI × clock period; improve any factor without making the others worse.
- The clock period must cover the slowest register-to-register path, plus clock-to-Q and setup times.
- Single-cycle datapaths have CPI 1 but a long period; multi-cycle designs shorten the period and raise CPI.
- Real-time code has a cycle budget per sample: clock rate ÷ sample rate.
Glossary
- Clock speed, cycles and CPI
- Execution time equals the number of instructions times the average cycles per instruction (CPI) divided by the clock frequency. Field Guide
- Propagation delay
- Propagation delay is the time a gate's output takes to respond to a change at its input. The slowest path between flip-flops, the critical path, sets the fastest safe clock. Field Guide
- D flip-flop
- A D flip-flop stores one bit. On each rising clock edge it copies its D input to its Q output and holds that value until the next edge. Field Guide
- Word size
- A processor's word size is the number of bits it naturally handles in one operation: its register width and usually its main data path. Field Guide
Project: Does the filter fit?
A sensor is sampled at a rate you choose between 1 and 20 kHz. Estimate the instruction count of a 16-tap filter, assume a CPI with stated reasons, and find the slowest clock that leaves 30 % headroom. Show the Iron Law calculation.
Deliverables
- Instruction-count estimate with assumptions
- Cycle budget per sample and headroom
- The chosen clock with a one-paragraph argument
Write it up on paper or in your own notes. Lite never stores what you write.
References
- John L. Hennessy and David A. Patterson (2017). Computer Architecture: A Quantitative Approach, 6th edition. Morgan Kaufmann.
- David A. Patterson and John L. Hennessy (2017). Computer Organization and Design RISC-V Edition: The Hardware Software Interface. Morgan Kaufmann.