CPU Time: The Performance Equation
The time a program takes is three numbers multiplied together: how many instructions it runs, how many clock cycles each one takes on average, and how long one cycle lasts. Shrink any one of them without growing the others and the program gets faster by exactly that factor.
What the symbols mean
- CPU time
Seconds the processor spends running the program.
- Instruction count
How many instructions the program actually executes (not how many lines it has).
- Cycles per instruction
The average number of clock cycles one instruction takes.
- Clock period
The length of one clock cycle, in seconds (often ns or ps).
- Clock rate
Cycles per second, f = 1/T_c (a 3 GHz clock ticks 3 × 10⁹ times a second).
What the symbols mean
- Times faster
X is n times faster than Y when Y takes n times as long.
Explanation
CPU time is simply how long the processor spends running your program, start to finish. The performance equation says it's three numbers multiplied together: (the instruction count, how many instructions the program executes), (cycles per instruction, how many ticks of the clock each one takes on average) and (the clock period, how long one tick lasts). It's the same reasoning as figuring out how long it takes to read a book: pages, times lines per page, times seconds per line. That's the whole equation, and the rest of this unit is about each piece.
Where it comes from. A processor runs to the beat of a clock. A clock rate of GHz means ticks per second, so one tick lasts
Every instruction takes some number of ticks. Add them up over the whole program and you get the total number of cycles, which is ; that's exactly what an average CPI means (the next lesson computes it from the kinds of instructions). Each of those cycles lasts , so
Watch the units cancel like a chain of conversion factors:
Dividing by is the same as multiplying by , which is why you'll see it written both ways.
Who controls each factor. The instruction count depends on the algorithm (a better big-O cuts it most), the compiler and the instruction set. CPI depends on the processor's design: pipelining, caches and branch prediction, which later units turn into formulas. The clock period is set by the slowest path a signal must travel in one cycle, like the carry rippling through an adder. The catch is that the three pull against each other: a simpler instruction set may lower CPI but raise IC, and a faster clock usually means doing less per cycle, which can raise CPI.
Faster means less time. Performance is defined as , so bigger is better. "X is times faster than Y" means
Notice the flip: the slower machine's time goes on top. If Y takes 15 s and X takes 10 s, X is times faster.
A common mistake. It's tempting to compare processors by clock rate alone, since gigahertz is the number on the box. It isn't enough. A 4 GHz machine with CPI 3 spends ns per instruction, while a 3 GHz machine with CPI 1.5 spends ns: the "slower" clock wins by a factor of 1.5. Only the full product tells you the time. A second slip: in the 15 s versus 10 s example, X is "50% faster" (performance went up by half), not "33% faster" (that's how much the time went down).
There's a graph further down that shows how much clock speed one machine needs just to tie another with a better CPI.
See it
Worked examples
A program executes instructions with an average CPI of on a GHz processor. How long does it run?
- 1
Write down what we know: instructions, cycles per instruction, and GHz.
Machine A has a GHz clock and runs a program with CPI . Machine B has a GHz clock and runs the same compiled program with CPI . Which is faster, and by how much? What clock rate would B need to tie A?
- 1
Both machines run the same compiled program, so the instruction count is the same on both. Call it ; we'll see it cancel.
Practice
Type your answer and check it. Solve them all to complete the lesson.
A program executes instructions with CPI on a GHz processor. What is its CPU time, in seconds?
A processor's clock period is ns. What is its clock rate, in GHz?
A simulation takes s on machine X and s on machine Y. How many times faster is X than Y?
A new compiler cuts a program's instruction count by , but the instructions it picks are more complex, so CPI rises from to . The clock doesn't change. What is the speedup (old time divided by new time)? Give 3 decimal places.
A real-time control loop executes instructions with CPI and must finish in s. What is the slowest clock rate that works, in GHz?
A simple processor finishes every instruction in one cycle, and its slowest path is a 32-bit ripple-carry adder where each full adder takes ps to pass its carry along. The clock period has to cover that whole path. What is the fastest clock rate, in MHz?
Machine P has a GHz clock and runs a program with CPI . Machine Q has a GHz clock and runs the same program with CPI . Which statement is true?
The hardest one here. Get it, and you've got this lesson.
A program runs on a GHz machine with and CPI . A redesign raises the clock rate by but raises CPI by , and a new compiler cuts the instruction count by . (a) What is the speedup of the new system over the old one? (b) What CPI would the new system need, with the same new clock and instruction count, to be times faster than the old one? Enter the speedup, then the CPI, each to 3 decimal places.
Where it's used
Whenever an engineering team argues about a design change, the performance equation is the scoreboard. A wider instruction set lowers IC, a deeper pipeline raises the clock rate, a bigger cache lowers CPI, and each change is judged by what it does to the product on real programs. Phone makers, for example, run their chips at several clock rates and pick the one that finishes a task in time with the least energy, a trade-off we'll put numbers on at the end of this unit.