Performance: CPI, MIPS and Amdahl's law
Measuring and comparing processors: CPU time as instruction count times CPI times clock period, average CPI from an instruction mix, MIPS and why it misleads, speedup, and Amdahl's law with its limit for one or several enhancements and for parallel processors.
Why it exists
Faster hardware is only useful if it reduces the time a program takes. This page gives the standard equation for that time, shows how the three factors (how many instructions, how many cycles each, how long a cycle) are traded against each other by the instruction set, the organization and the technology, and states the law that limits what any single improvement can give: Amdahl's law. GATE uses it constantly, in the form "this much of the time is sped up by this factor, what is the overall speedup?", and in CPI, MIPS and execution-time comparisons.
Prerequisites
You need the idea of cycles per instruction, introduced with pipelining and used in pipeline performance.
Precise definitions
CPU performance equation.
- Instruction count (IC) depends on the program, the compiler and the instruction set.
- CPI (cycles per instruction) depends on the organization (pipelining, caches) and the instruction mix.
- Clock period depends on the technology and the organization (the slowest stage).
An improvement in one factor can worsen another: a richer instruction set lowers IC but may raise CPI or lengthen the clock period.
Average CPI from an instruction mix. With classes of frequency (fractions of the instructions) and cycles ,
The cycles for the program are ; with cache misses or pipeline stalls add the stall cycles per instruction to the CPI (cache performance, pipeline performance).
MIPS (million instructions per second).
MIPS depends on the instruction set (what an instruction does), so it cannot compare machines with different instruction sets or compilers, and it can even rank a machine as faster when it is slower. MFLOPS counts floating-point operations per second and has similar problems. The only reliable comparison is execution time of real programs.
Speedup and relative performance. Performance is the reciprocal of execution time. "A is times faster than B" means , and the speedup from a change is .
Amdahl's law. If an enhancement speeds up a part of the program that takes a fraction of the original execution time by a factor , the new time is (relative to the old one), so
The part that is not enhanced, , is unchanged. Even if the speedup cannot exceed
It shows diminishing returns: making the same part ever faster brings less and less, and the best use of effort is the part with the largest remaining share of the time. For several enhancements on separate parts with fractions and speedups ,
For a program with a parallel fraction run on processors, gives the speedup and the limit however many processors are used.
Required enhancement. To reach an overall speedup by enhancing a fraction the part must be sped up by
which is possible only if .
How it works
The explorer applies the law. Set the fraction of the original time that is enhanced and the speedup of that part. The bar shows the new execution time (the grey unchanged part never shrinks; only the blue part does), and the curve shows how the overall speedup flattens against its limit as the enhancement gets larger. Try 50% with the enhancement at 100x and see how little is gained; then try 95%.
New execution time (old time = 1)
New time = (1 - f) + f/s = 0.200 + 0.160 = 0.360
Worked examples
EX 1Average CPI, execution time and MIPS
EasyA 2 GHz processor runs a program of instructions: 50% ALU (CPI 1), 20% loads (CPI 2), 10% stores (CPI 2) and 20% branches (CPI 3).
#include <stdio.h>
int main(void) {
/* instruction mix and CPI per class */
const char *name[4] = {"ALU", "load", "store", "branch"};
double freq[4] = {0.50, 0.20, 0.10, 0.20}, cpi[4] = {1, 2, 2, 3};
double avg = 0;
for (int i = 0; i < 4; i++) {
avg += freq[i] * cpi[i];
printf("%-6s %.0f%% x CPI %.0f = %.2f\n", name[i], 100 * freq[i], cpi[i], freq[i] * cpi[i]);
}
double clock = 2e9, ic = 1e9;
printf("average CPI = %.2f\n", avg);
printf("CPU time for %.0e instructions at %.0f GHz = %.3f s\n", ic, clock / 1e9, ic * avg / clock);
printf("MIPS = %.1f\n", clock / (avg * 1e6));
return 0;
}ALU 50% x CPI 1 = 0.50
load 20% x CPI 2 = 0.40
store 10% x CPI 2 = 0.20
branch 20% x CPI 3 = 0.60
average CPI = 1.70
CPU time for 1e+09 instructions at 2 GHz = 0.850 s
MIPS = 1176.5Reading it. CPI is the frequency-weighted average of the class CPIs: . Time s. MIPS , which also equals .
EX 2Why MIPS can mislead
MediumThe same program on two 1 GHz machines. Machine M1 has simple instructions: the program needs of them at CPI 1. Machine M2 has richer instructions: of them at CPI 1.5.
#include <stdio.h>
int main(void) {
/* the same program on two machines at 1 GHz: M1 needs 2e9 simple instructions at CPI 1, M2 needs 1e9 complex ones at CPI 1.5 */
double clock = 1e9;
double ic1 = 2e9, cpi1 = 1.0, ic2 = 1e9, cpi2 = 1.5;
printf("M1: MIPS %.0f, time %.2f s\n", clock / (cpi1 * 1e6), ic1 * cpi1 / clock);
printf("M2: MIPS %.0f, time %.2f s\n", clock / (cpi2 * 1e6), ic2 * cpi2 / clock);
return 0;
}M1: MIPS 1000, time 2.00 s
M2: MIPS 667, time 1.50 sReading it. M1 has the higher MIPS rating but takes longer (2.00 s against 1.50 s): its instructions do less. Comparing MIPS is only meaningful for the same instruction set and program. Execution time is the measure; M2 is times faster.
EX 3Amdahl's law, several ways
Medium#include <stdio.h>
static double amdahl(double f, double s) { return 1 / (1 - f + f / s); }
int main(void) {
printf("f = 0.8, s = 4: speedup %.3f, limit %.2f\n", amdahl(0.8, 4), 1 / (1 - 0.8));
/* two enhancements on disjoint parts: 40% sped up 2x and 30% sped up 3x, 30% unchanged */
printf("two parts: speedup %.3f\n", 1 / (0.3 + 0.4 / 2 + 0.3 / 3));
/* 90%% parallelisable on 10 processors */
printf("90%% parallel on 10 processors: %.2f (limit %.0f)\n", amdahl(0.9, 10), 1 / (1 - 0.9));
/* what enhancement of 80% of the time gives an overall speedup of 3? */
double f = 0.8, target = 3, s = f / (1 / target - (1 - f));
printf("overall speedup %.0f needs the 80%% part %.2f times faster (check: %.3f)\n", target, s, amdahl(f, s));
/* the share of the NEW time that is spent in the enhanced part */
double new_time = 1 - 0.8 + 0.8 / 4;
printf("after the f = 0.8, s = 4 change the enhanced part is %.0f%% of the new time\n", 100 * (0.8 / 4) / new_time);
return 0;
}f = 0.8, s = 4: speedup 2.500, limit 5.00
two parts: speedup 1.667
90% parallel on 10 processors: 5.26 (limit 10)
overall speedup 3 needs the 80% part 6.00 times faster (check: 3.000)
after the f = 0.8, s = 4 change the enhanced part is 50% of the new timeReading it. (1) New time , speedup ; the limit is even for an infinitely fast enhancement. (2) Disjoint parts: , speedup . (3) With 10 processors a 90% parallel program is only 5.26 times faster, and never more than 10. (4) Solving for : ; the target 5 would be impossible, as it equals the limit. (5) After the change, the enhanced part takes of a total new time : 50%. This is a typical trap: the fraction of the new time differs from the fraction of the old time.
EX 4An improvement to part of the instruction mix
GATE levelA machine spends 40% of its time on floating-point instructions. A change makes all floating-point instructions twice as fast, and another change makes the 30% of time spent in loads and stores 3 times as fast. The rest (30%) is unchanged. Using the multi-part form, new time , so the speedup is , the value computed in example 3. Each change alone gives new time and speedup . Together they give , not , because both fractions are fractions of the original time: apply the second change to the program after the first and its share of the time has grown from to , giving a further , and . Always check that the fractions refer to time, not to the number of instructions.
EX 5CPU time with a clock and CPI change
GATE levelA program has , CPI 1.5, clock 2 GHz. A redesign raises the clock to 2.5 GHz but the CPI rises to 1.9 because of a longer pipeline's stalls. Old time s. New time s. The redesign is slightly slower even though the clock is 25% higher: the CPI went up by 26.7%. Compare the product , not the clock alone.
Cheat box
Cheat box
- CPU time .
- Average CPI . With stalls, add stall cycles per instruction.
- MIPS . Only compare MIPS on the same instruction set and program.
- Speedup old time new time. "Faster by 25%" means speedup .
- Amdahl: speedup , a fraction of the ORIGINAL time. Limit .
- Several parts: .
- Required ; impossible if .
- Parallel: processors; the serial fraction caps the speedup.
Traps and GATE patterns
Connections
Builds on
Across subjects
No cross-subject links yet.
The CPI used here is the one the pipeline makes close to 1 and hazards push up; the memory stall cycles per instruction of cache performance are added the same way. The trade between IC and CPI is the design question of ISA design: a richer instruction lowers IC and tends to raise CPI. The number of cycles each instruction takes comes from the instruction cycle.
PYQs
2 previous year questions from your book. I re-solved each one myself (2 by running or simulating, 0 by reasoning only); the book's key is shown next to my answer. All PYQs
The baseline execution time of a program on a 2GHz single core machine is 100 nanoseconds (ns). The code corresponding to 90% of the execution time can be fully parallelized. The overhead for using an additional core is 10 ns when running on a multicore system. Assume that all cores in the multicore system run their share of the parallelized code for an equal amount of time. The number of cores that minimize the execution time of the program is .
An application executes 6.4 × 108 number of instructions in 6.3 seconds. There are four types of instructions, the details of which are given in the table. The duration of a clock cycle in nanoseconds is (rounded off to one decimal place). Instruction type Clock cycles required per instruction (CPI) Number of instruction executed Branch 2 2.25 × 108 Load 5 1.20 × 108 Store 4 1.65 × 108 Arithmetic 3 1.30 × 108 3 3 Computer Organization and Architecture
Self-check
Question 1
A program has 60% of its time in a part that is made 5 times faster. Overall speedup, and the limit?
Show answerHide
New time ; speedup . Limit .
Question 2
A 1.5 GHz machine runs a program of instructions at average CPI 2. Time and MIPS?
Show answerHide
Time s. MIPS .
Question 3
What speedup of a part that takes 50% of the time is needed for an overall speedup of 1.6?
Show answerHide
.
Question 4
Can any enhancement of 25% of the time give an overall speedup of 2?
Show answerHide
No. The limit is .
Revision card
One-screen revision
- Time . CPI (plus stalls).
- MIPS ; misleading across instruction sets.
- Amdahl: with of the original time; limit .
- Multiple parts: one denominator. Required .
- Parallel: serial fraction caps the speedup.
References
- ·Hennessy and Patterson, Computer Organization and Design, Chapter 1 Computer Abstractions and Technology (performance, the CPU performance equation, MIPS, Amdahl's law)
- ·Hamacher, Vranesic, Zaky, Computer Organization, 5th ed., Chapter 1 (performance) and the performance sections of the pipelining chapter
- ·Stallings, Computer Organization and Architecture, Computer performance chapter (clock speed and CPI, MIPS, Amdahl's law)
Verification
Every number is produced by the C programs on this page (npm run verify:c). Amdahl's law is implemented once in src/lib/sim/amdahl.ts for the interactive explorer and tested in tests/amdahl.test.ts (textbook values, agreement with the time breakdown, the limit, and that the required-enhancement formula inverts the law). The page uses the standard definitions: speedup is old time divided by new time, and the fraction in Amdahl's law is a fraction of the ORIGINAL execution time (not of instructions) unless a question states otherwise. MIPS is defined as clock rate divided by CPI times 10^6, the form GATE uses. Textbook chapter titles are from memory. SECOND PASS (2026-11-02, done by the assistant, not a human check): every Self-check question was solved before the printed answer was read and all agreed; the definitions, worked examples, cheat box and traps were read claim by claim and the numbers re-derived by hand (long C programs were not re-read line by line: they are compiled and compared by npm run verify:c, and their printed outputs were checked against the prose). No defect found. Status raised to self-checked; verified needs a textbook or human check.
last verified: never
My notes (saved in this browser)