Computer Architecture Cheatsheet

Performance

Use this Computer Architecture reference while you build software engineering projects, review code for technical interview prep, or polish examples for a software engineer resume.

The Iron Law of Performance

CPU Time = Instruction Count × CPI × Clock Cycle Time

Or equivalently:

CPU Time = (Instruction Count × CPI) / Clock Rate

VariableSymbolDetermined by
Instruction countICAlgorithm, compiler, ISA
Cycles per instructionCPIMicroarchitecture (pipeline, OOO, caches)
Clock cycle timeT = 1/fImplementation (process node, circuit design)

These three variables trade off. RISC reduces CPI but may increase IC vs CISC; deeper pipelines increase f but raise branch penalty (CPI).

CPI Breakdown

Effective CPI = Base CPI + Memory stall CPI + Branch stall CPI + ...

SourceCPI contribution formula
Load-use stallsfreq_load_use × 1 cycle
Branch mispredictionsfreq_branch × miss_rate × penalty
L1 data missesmem_accesses_per_instr × L1_miss_rate × L2_hit_time
L2 missesmem_accesses_per_instr × L2_miss_rate × memory_time

Example: - Base CPI = 1.0 - Branch freq = 15%, miss rate = 8%, penalty = 14 cycles → +0.168 - Load freq = 30%, L1 miss rate = 4%, L2 hit = 10 cycles → +0.12 - L2 miss rate = 1%, memory = 200 cycles → +0.06 - Effective CPI = 1 + 0.168 + 0.12 + 0.06 = 1.348

Speedup

Speedup = Old time / New time = 1 / ((1 − f) + f/s)

Where f = fraction of execution improved, s = speedup of that fraction.

This is Amdahl's Law in execution-time form.

Example: If 70% of time is in a routine sped up 10×:

Speedup = 1 / (0.30 + 0.70/10) = 1 / (0.30 + 0.07) = 1 / 0.37 ≈ 2.70×

Even though the routine is 10× faster, overall speedup is only 2.70×.

Benchmarks

SPEC CPU Benchmarks

SuiteFocusExample workloads
SPECint (CINT2017)Integer performanceGCC, Perl, x264, mcf
SPECfp (CFP2017)Floating-pointBLAS, weather sim, fluid dynamics
SPECrateThroughput (multi-core)Run N copies simultaneously
SPECspeedLatency (single thread)One copy, minimize time

SPEC ratio = reference time / measured time. Geometric mean across all benchmarks.

Other Common Benchmarks

BenchmarkMeasures
LINPACK / HPLPeak FP throughput (Top500 HPC ranking)
STREAMMemory bandwidth (4 kernels: copy, scale, add, triad)
LMbenchDetailed latency/bandwidth (memory, syscall)
DhrystoneInteger/compiler throughput (old; not representative)
GeekbenchConsumer single/multi-core (opaque; use with skepticism)
MLPerfML training and inference throughput
PARSECParallel workloads (shared-memory multicore)

Benchmark pitfalls: peak performance ≠ sustained; microbenchmarks may not predict real workload performance; compiler flags and libraries dramatically affect results.

Memory Performance Metrics

MetricFormulaTypical values
AMATHit time + Miss rate × Miss penalty1–10 cycles typical
BandwidthWidth × frequency50–100+ GB/s (DDR5 dual-channel)
Memory-level parallelism (MLP)Avg. concurrent outstanding misses8–16 for out-of-order CPUs

STREAM Benchmark Kernel Bandwidths (indicative)

KernelOperations
Copya[i] = b[i]
Scalea[i] = k × b[i]
Adda[i] = b[i] + c[i]
Triada[i] = b[i] + k × c[i] (main kernel)

Roofline Model

The Roofline model identifies whether a kernel is compute-bound or memory-bandwidth-bound.

Performance      │           ╱ Roofline
(GFLOPS/s)       │          ╱
                 │  Memory ╱  ─────────── Peak compute
                 │  bound ╱  Compute
                 │       ╱   bound
                 └──────────────────────────
                       Arithmetic Intensity
                       (FLOPS / byte)

Arithmetic Intensity (AI) = FLOPS / bytes transferred from DRAM

Ridge point = Peak compute / Peak bandwidth

RegimeConditionBottleneckFix
Memory-boundAI < Ridge pointDRAM bandwidthBetter cache use, prefetch, compression
Compute-boundAI > Ridge pointALU throughputVectorize, fuse ops, reduce precision

Example (H100): Peak FP32 = 67 TFLOPS, Memory BW = 3.35 TB/s → Ridge point = 67,000 / 3,350 ≈ 20 FLOP/byte

Dense matrix multiply (GEMM) has AI ≈ N/2 (for N×N matrix) → compute-bound for any reasonable N.

Measuring Performance

Tool (Linux)What it measures
perf statHardware PMU: cycles, instructions, cache misses, branch mispredictions
perf record/reportCall-graph profiling with hardware counters
valgrind --tool=cachegrindSimulated cache miss rates
vtune (Intel)Detailed microarchitecture analysis
gprofSampling profiler (software, low overhead)
timeWall time, user time, system time
sar, iostatSystem-wide CPU, I/O utilization

Key PMU Events (x86)

EventCounter name
Clock cyclescpu-cycles
Instructions retiredinstructions
L1D missesL1-dcache-load-misses
LLC missesLLC-load-misses
Branch mispredictionsbranch-misses
dTLB missesdTLB-load-misses

IPC from perf:

perf stat -e cycles,instructions ./program
# instructions / cycles = IPC

Power-Performance Trade-offs

MetricFormulaNotes
EnergyE = P × timeJoules
Energy-delay product (EDP)EDP = E × time = P × time²Balances energy and speed equally
Energy-delay² product (ED²P)ED²P = E × time² = P × time³Weights delay more heavily — favors performance
Performance per wattGFLOPS/W or IPS/WMobile / HPC efficiency metric

Dennard Scaling (ended ~2005): as transistors shrink, voltage drops → power stays constant at same performance. Breakdown: leakage current no longer shrinks proportionally → power density rises → "power wall."

The Power Wall: CPUs can no longer increase clock speed without unacceptable power/thermal cost. Response: more cores at lower frequency.

Performance Summary Table

TechniqueReducesAffects
Better algorithmInstruction countIC ↓
Better compilerIC, CPIIC ↓, CPI ↓
Bigger cachesCache miss stallsCPI ↓
Out-of-order executionILP stallsCPI ↓
Branch predictionControl stallsCPI ↓
Higher clock rateCycle timeT ↓ (but CPI may ↑ with deeper pipe)
SIMD / vectorizationInstruction countIC ↓ (same work, fewer instructions)
More cores (parallel code)Wall-clock timeTime ↓ (IC × CPI × T unchanged per thread)
DVFS / power gatingPowerE ↓ (some T ↑ trade-off)