Sub topic 5
Speedup, throughput, and efficiency
This chapter assumes you know the five pipeline stages (IF, ID, EX, MEM, WB) and how a timing diagram shows instructions overlapping. It also assumes you are comfortable with ratios and with the clock period as the time of one cycle. Here you will turn those pictures into three numbers: speedup, throughput, and efficiency. GATE asks for these numbers often.
Total time for n instructions
In a k-stage pipeline, the first instruction needs k cycles to pass through all stages. After that, one instruction finishes each cycle. So n instructions need:
- cycles = k + (n − 1)
- time = (k + n − 1) × clock period
The clock period is set by the slowest stage plus the delay of the pipeline register (latch) that follows each stage:
- clock period = max(stage delays) + latch delay
A non-pipelined machine runs each instruction through all stages in one long cycle. Its time is n × (sum of stage delays). It has no latches, so it pays no latch delay. Some GATE questions give a different non-pipelined cycle time. Always use the number the question gives.
Speedup
Speedup is the ratio of the two times:
- S = T(non-pipelined) / T(pipelined)
Work through a concrete case in code. The stage delays are 60, 80, 70, 90, and 50 ns, the latch delay is 10 ns, and n is 100.
def pipelined_time(stage_delays, latch_delay, n, stall_cycles=0):
# The clock period is set by the slowest stage plus the pipeline-register delay.
clock = max(stage_delays) + latch_delay
k = len(stage_delays)
return (k + n - 1 + stall_cycles) * clock
def non_pipelined_time(stage_delays, n):
return n * sum(stage_delays)
delays = [60, 80, 70, 90, 50] # ns per stage
n = 100
tp = pipelined_time(delays, 10, n) # (5 + 99) * 100 = 10400 ns
tn = non_pipelined_time(delays, n) # 100 * 350 = 35000 ns
print(tp, tn, round(tn / tp, 2)) # 10400 35000 3.37The speedup is about 3.37, well below the stage count of 5. Two things cost us. The slowest stage (90 ns) sets a 100 ns clock, so the 50 ns stage sits idle for half of every cycle. The 10 ns latch delay is also added to every cycle.
The ideal case
Suppose all stages have equal delay t, there is no latch delay, and there are no stalls. Then:
- T(non-pipelined) = n × k × t
- T(pipelined) = (k + n − 1) × t
- S = n·k / (k + n − 1)
As n grows large, S approaches k. That is the upper limit: a k-stage pipeline cannot be more than k times faster than the same work done unpipelined.
Throughput
Throughput is the number of instructions completed per unit time. There are two versions, and questions may ask for either.
- Steady-state throughput is 1 / clock period. Once the pipeline is full, one instruction finishes per cycle. With a 100 ns clock this is 10 million instructions per second (10 MIPS).
- Actual throughput is n / total time. It includes the cycles spent filling the pipeline, so it is always a little lower.
The next function computes all three metrics at once.
def pipeline_metrics(stage_delays, latch_delay, n):
k = len(stage_delays)
clock = max(stage_delays) + latch_delay
t_pipe = (k + n - 1) * clock
t_flat = n * sum(stage_delays)
speedup = t_flat / t_pipe
return {
"clock_ns": clock,
"speedup": round(speedup, 3),
"steady_mips": 1000 / clock, # instructions per microsecond
"actual_mips": round(n / t_pipe * 1000, 3),
"efficiency": round(speedup / k, 3),
}
print(pipeline_metrics([60, 80, 70, 90, 50], 10, 100))
# {'clock_ns': 100, 'speedup': 3.365, 'steady_mips': 10.0,
# 'actual_mips': 9.615, 'efficiency': 0.673}Dividing by the time in nanoseconds and multiplying by 1000 converts instructions per nanosecond to instructions per microsecond, which equals MIPS.
Efficiency
Efficiency tells you how much of the pipeline's potential you actually use. The usual definition is:
- efficiency = speedup / k
For the example, 3.365 / 5 = 0.673, or about 67%. An ideal pipeline with no latch cost and no stalls has efficiency n / (k + n − 1). That value is below 1 only because of the fill time. For n = 100 and k = 5 it is 100 / 104, about 96%.
What reduces speedup
| Cause | Effect on the numbers |
|---|---|
| Fill time (small n) | Total cycles k + n − 1 instead of n |
| Unbalanced stages | Clock set by the slowest stage; faster stages idle |
| Latch delay | Added to every clock period |
| Stalls and bubbles | Extra cycles added to the total |
| Branch flushes | Wasted cycles after each mispredicted branch |
Stalls enter the formula directly. If the program suffers s stall cycles in total, the pipelined time becomes (k + n − 1 + s) × clock. The stall_cycles parameter of pipelined_time handles this. Later chapters show how to count s from hazards and how to express it as an effective CPI.
Worked method for exam questions
- Find the clock period: the maximum stage delay plus the latch delay.
- Count the pipelined cycles: k + n − 1, plus any stall cycles.
- Multiply cycles by the clock period for the pipelined time.
- Compute the non-pipelined time as given by the question, usually n × (sum of stage delays).
- Divide to get speedup. Divide the speedup by k for efficiency, and n by the pipelined time for throughput.
Common mistakes
- Using the sum of the stage delays as the pipelined clock. The clock is the maximum, not the sum.
- Forgetting the latch delay in the pipelined clock, or wrongly adding it to the non-pipelined time.
- Using n × k cycles for the pipelined time. The correct count is k + n − 1.
- Expecting speedup to equal k. It equals k only in the limit of large n with balanced stages, no latch cost, and no stalls.
Exercise
A 4-stage pipeline has stage delays of 5, 6, 11, and 8 ns and a latch delay of 1 ns. It runs 1000 instructions with no stalls. Find the speedup over a non-pipelined machine (no latch delay) and the efficiency.
Show answer
The clock is 11 + 1 = 12 ns. Pipelined time is (4 + 999) × 12 = 12036 ns. Non-pipelined time is 1000 × (5 + 6 + 11 + 8) = 30000 ns. Speedup = 30000 / 12036 ≈ 2.49. Efficiency = 2.49 / 4 ≈ 0.62, or about 62%.
Exercise
For an ideal 5-stage pipeline with equal stage delays, no latch delay, and no stalls, what is the smallest number of instructions n for which the speedup reaches at least 4.5?
Show answer
S = 5n / (n + 4). Setting 5n / (n + 4) ≥ 4.5 gives 5n ≥ 4.5n + 18, so 0.5n ≥ 18 and n ≥ 36. The smallest n is 36.