G27
Self-checkedTier 1 12 min readcoa.amdahl-performance

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.

CPU time=instruction count×CPI×clock period=IC×CPIclock rate.\text{CPU time} = \text{instruction count} \times \text{CPI} \times \text{clock period} = \frac{\text{IC} \times \text{CPI}}{\text{clock rate}}.

  • 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 ii of frequency fif_i (fractions of the instructions) and cycles CPIi\text{CPI}_i,

CPI=∑ifi CPIi.\text{CPI} = \sum_i f_i\,\text{CPI}_i.

The cycles for the program are IC×CPI\text{IC} \times \text{CPI}; 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=ICtime×106=clock rateCPI×106.\text{MIPS} = \frac{\text{IC}}{\text{time} \times 10^6} = \frac{\text{clock rate}}{\text{CPI} \times 10^6}.

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 nn times faster than B" means timeB/timeA=n\text{time}_B/\text{time}_A = n, and the speedup from a change is timeold/timenew\text{time}_{old}/\text{time}_{new}.

Amdahl's law. If an enhancement speeds up a part of the program that takes a fraction ff of the original execution time by a factor ss, the new time is (1−f)+f/s(1 - f) + f/s (relative to the old one), so

overall speedup=1(1−f)+f/s.\text{overall speedup} = \frac{1}{(1 - f) + f/s}.

The part that is not enhanced, 1−f1 - f, is unchanged. Even if s→∞s \to \infty the speedup cannot exceed

limit=11−f.\text{limit} = \frac{1}{1 - f}.

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 f1,f2,…f_1, f_2, \ldots and speedups s1,s2,…s_1, s_2, \ldots,

speedup=1(1−∑fj)+∑fj/sj.\text{speedup} = \frac{1}{(1 - \sum f_j) + \sum f_j / s_j}.

For a program with a parallel fraction ff run on pp processors, s=ps = p gives the speedup 1/((1−f)+f/p)1/((1 - f) + f/p) and the limit 1/(1−f)1/(1 - f) however many processors are used.

Required enhancement. To reach an overall speedup SS by enhancing a fraction ff the part must be sped up by

s=f1/S−(1−f),s = \frac{f}{1/S - (1 - f)},

which is possible only if S<1/(1−f)S < 1/(1 - f).

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)

unchanged 0.20
enhanced 0.16

New time = (1 - f) + f/s = 0.200 + 0.160 = 0.360

overall speedup
2.778x
limit (s to infinity)
5.00x
share of the limit reached
56%
110100speedup of the enhanced part (log scale)overall

Worked examples

EX 1Average CPI, execution time and MIPS

Easy

A 2 GHz processor runs a program of 10910^9 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.5

Reading it. CPI is the frequency-weighted average of the class CPIs: 0.5+0.4+0.2+0.6=1.70.5 + 0.4 + 0.2 + 0.6 = 1.7. Time =109×1.7/(2×109)=0.85= 10^9 \times 1.7 / (2 \times 10^9) = 0.85 s. MIPS =2000/1.7=1176.5= 2000/1.7 = 1176.5, which also equals IC/(time×106)=1000/0.85\text{IC}/(\text{time} \times 10^6) = 1000/0.85.

EX 2Why MIPS can mislead

Medium

The same program on two 1 GHz machines. Machine M1 has simple instructions: the program needs 2×1092 \times 10^9 of them at CPI 1. Machine M2 has richer instructions: 10910^9 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 s

Reading 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 2.00/1.50=1.332.00/1.50 = 1.33 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 time

Reading it. (1) New time =0.2+0.8/4=0.4= 0.2 + 0.8/4 = 0.4, speedup 2.52.5; the limit is 1/0.2=51/0.2 = 5 even for an infinitely fast enhancement. (2) Disjoint parts: 0.3+0.2+0.1=0.60.3 + 0.2 + 0.1 = 0.6, speedup 1.6671.667. (3) With 10 processors a 90% parallel program is only 5.26 times faster, and never more than 10. (4) Solving for ss: 0.8/(1/3−0.2)=60.8/(1/3 - 0.2) = 6; the target 5 would be impossible, as it equals the limit. (5) After the change, the enhanced part takes 0.20.2 of a total new time 0.40.4: 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 level

A 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 =0.3+0.4/2+0.3/3=0.3+0.2+0.1=0.6= 0.3 + 0.4/2 + 0.3/3 = 0.3 + 0.2 + 0.1 = 0.6, so the speedup is 1/0.6=1.6671/0.6 = 1.667, the value computed in example 3. Each change alone gives new time 0.80.8 and speedup 1.251.25. Together they give 1.6671.667, not 1.25×1.25=1.56251.25 \times 1.25 = 1.5625, 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 0.30.3 to 0.3/0.8=0.3750.3/0.8 = 0.375, giving a further 1.3331.333, and 1.25×1.333=1.6671.25 \times 1.333 = 1.667. Always check that the fractions refer to time, not to the number of instructions.

EX 5CPU time with a clock and CPI change

GATE level

A program has IC=4×109\text{IC} = 4 \times 10^9, 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 =4×109×1.5/(2×109)=3= 4 \times 10^9 \times 1.5 / (2 \times 10^9) = 3 s. New time =4×109×1.9/(2.5×109)=3.04= 4 \times 10^9 \times 1.9 / (2.5 \times 10^9) = 3.04 s. The redesign is slightly slower even though the clock is 25% higher: the CPI went up by 26.7%. Compare the product CPI×clock period\text{CPI} \times \text{clock period}, not the clock alone.

Cheat box

Cheat box

  • CPU time =IC×CPI×Tclk=IC×CPI/fclk= \text{IC} \times \text{CPI} \times T_{clk} = \text{IC} \times \text{CPI} / f_{clk}.
  • Average CPI =∑fi CPIi= \sum f_i\,\text{CPI}_i. With stalls, add stall cycles per instruction.
  • MIPS =fclk/(CPI×106)= f_{clk}/(\text{CPI} \times 10^6). Only compare MIPS on the same instruction set and program.
  • Speedup == old time // new time. "Faster by 25%" means speedup 1.251.25.
  • Amdahl: speedup =1/((1−f)+f/s)= 1/((1 - f) + f/s), ff a fraction of the ORIGINAL time. Limit 1/(1−f)1/(1 - f).
  • Several parts: 1/((1−∑fj)+∑fj/sj)1/((1 - \sum f_j) + \sum f_j/s_j).
  • Required s=f/(1/S−(1−f))s = f/(1/S - (1 - f)); impossible if S≥1/(1−f)S \ge 1/(1 - f).
  • Parallel: s=ps = p processors; the serial fraction caps the speedup.

Traps and GATE patterns

Connections

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

GATE 2024 · NATQ8 · page 455 of the book
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
.
GATE 2025 · NATQ4 · page 474 of the book
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 answer

New time =0.4+0.6/5=0.52= 0.4 + 0.6/5 = 0.52; speedup =1/0.52=1.92= 1/0.52 = 1.92. Limit =1/0.4=2.5= 1/0.4 = 2.5.

Question 2

A 1.5 GHz machine runs a program of 6×1096 \times 10^9 instructions at average CPI 2. Time and MIPS?

Show answer

Time =6×109×2/(1.5×109)=8= 6 \times 10^9 \times 2 / (1.5 \times 10^9) = 8 s. MIPS =1500/2=750= 1500/2 = 750.

Question 3

What speedup of a part that takes 50% of the time is needed for an overall speedup of 1.6?

Show answer

s=0.5/(1/1.6−0.5)=0.5/0.125=4s = 0.5/(1/1.6 - 0.5) = 0.5/0.125 = 4.

Question 4

Can any enhancement of 25% of the time give an overall speedup of 2?

Show answer

No. The limit is 1/(1−0.25)=1.331/(1 - 0.25) = 1.33.

Revision card

One-screen revision

  • Time =IC×CPI/fclk= \text{IC} \times \text{CPI}/f_{clk}. CPI =∑fi CPIi= \sum f_i\,\text{CPI}_i (plus stalls).
  • MIPS =fclk/(CPI×106)= f_{clk}/(\text{CPI} \times 10^6); misleading across instruction sets.
  • Amdahl: 1/((1−f)+f/s)1/((1 - f) + f/s) with ff of the original time; limit 1/(1−f)1/(1 - f).
  • Multiple parts: one denominator. Required s=f/(1/S−(1−f))s = f/(1/S - (1 - f)).
  • 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