# Performance Trade-offs

Computer Science I · Introduction to Computers · https://tryals.app/learn/computer-science-i/performance-trade-offs

## What Fast Really Means

Raw **clock speed** in GHz is the most quoted chip metric, but on its own it is a poor guide. Real performance depends on three factors multiplied together, captured by the **CPU performance equation**:

$$\text{time} = \text{instructions} \times \text{CPI} \times \text{time per cycle}$$

Here, **instructions** is total count, **CPI** is cycles per instruction, and **time per cycle** is the inverse of clock speed. A slower clock with lower CPI or fewer total instructions often beats a higher-GHz rival.

| Feature | Benefit | Cost / Trade-off |
| --- | --- | --- |
| **Cache** | Speeds up memory access | Costs chip area and power |
| **Pipeline** | Raises instruction throughput | Complicates control, risks stalls |
| **Cores** | Enables parallel execution | Useless for sequential tasks |

**Common Pitfall:** Judging a processor purely by clock speed (the megahertz myth). Architecture and instruction count matter just as much.

## Amdahl's Law and Limits

More cores help programs split into parallel work, but do nothing for tasks that are inherently sequential. This is formalized by **Amdahl's law**, which limits total speedup based on the non-parallelizable fraction.

$$S_{max} = \frac{1}{(1-p) + \frac{p}{N}}$$

In the formula, **p** is the parallel fraction and **N** is the number of processors. If 10 percent of a task is serial, **1 - p** is 0.10. Even with infinite processors, the speedup can never exceed 10 times because the serial part dominates.

**Key Distinction:** **Clock speed** measures raw cycle rate, but **performance** measures actual work done over time. Similarly, **cores** add raw capacity, but **Amdahl's law** proves that sequential bottlenecks cap the gains.

## Practice questions

3 of this lesson's 11 practice questions, with answers. The full set is in the app.

### 1. Select every statement that genuinely follows from the CPU performance equation and Amdahl's law.

A. A program that is 50 percent sequential can never be sped up more than 2 times, however many cores are added
B. Reducing the number of instructions executed reduces the run time, all else being equal
C. A 3 GHz chip is always faster than a 2 GHz chip
D. Doubling the number of cores doubles the speed of any program
E. Halving the cycles per instruction halves the run time, at a fixed clock and instruction count

**Answer:** A. A program that is 50 percent sequential can never be sped up more than 2 times, however many cores are added; B. Reducing the number of instructions executed reduces the run time, all else being equal; E. Halving the cycles per instruction halves the run time, at a fixed clock and instruction count

**Why:** The equation is a product of three factors, so halving one of them halves the time when the others are fixed, which validates options 2 and 5 and destroys option 3, since a faster clock says nothing about CPI. Amdahl's law caps the speedup at 1 divided by the sequential fraction, so a half-sequential program stops at 2 times, and option 4 is false for exactly that reason.

Page: https://tryals.app/practice/computer-science-i/performance-trade-offs/select-every-statement-that-genuinely-follows-from-the-cpu

### 2. Every program is compiled as though it owns memory starting at address zero, and thousands run at once without colliding. What makes that possible?

A. Programs being allocated non-overlapping address ranges at compile time
B. The operating system rewriting each program's addresses as it loads
C. Virtual memory, each process getting its own translated address space
D. The compiler generating position-independent code that avoids fixed addresses

**Answer:** C. Virtual memory, each process getting its own translated address space

**Why:** The MMU translates each process's virtual addresses to distinct physical pages, so identical addresses mean different memory, which gives isolation for free and lets programs be written without knowing what else is running. A wild pointer then hits your own address space rather than someone else's, which is what makes a crash a crash and not a corruption.

Page: https://tryals.app/practice/computer-science-i/performance-trade-offs/every-program-is-compiled-as-though-it-owns-memory-starting-at

### 3. An operating system gives each program the illusion of having the whole machine to itself. Why is that illusion worth the overhead of maintaining it?

A. Because the illusion is free, requiring no runtime overhead once set up.
B. Because it makes programs run faster than they would with direct hardware access.
C. Because hardware cannot be accessed directly by more than one program at a time under any circumstances.
D. Because a program need not know what else runs or where its memory sits.

**Answer:** D. Because a program need not know what else runs or where its memory sits.

**Why:** Without the abstraction every program would need to know what else was running and which physical addresses were free, and one stray write would corrupt any other. The overhead is genuine — page walks, TLB misses, context switches — and specialised systems give it up: HFT pins cores and bypasses the kernel's network stack. Worth its price in general, not universally.

Page: https://tryals.app/practice/computer-science-i/performance-trade-offs/an-operating-system-gives-each-program-the-illusion-of-having-the
