Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Performance

Overview

Understanding computer performance — how to measure, analyze, and optimize it — is critical for placement interviews. This section covers Amdahl’s Law (the limits of parallel speedup), the CPU performance equation, benchmarking methodologies, and hardware performance counters.

Performance Metrics

MetricDescriptionFormula
LatencyTime to complete one taskTime / Task
ThroughputTasks completed per unit timeTasks / Time
BandwidthData transferred per unit timeBytes / Time
CPICycles per instructionCycles / Instructions
IPCInstructions per cycleInstructions / Cycles
FLOPSFloating-point operations per secondFLOPs / Time

Latency vs Throughput

graph LR
    subgraph "Latency-Optimized"
        CPU["CPU<br/>Fast single task<br/>Low latency"]
    end
    subgraph "Throughput-Optimized"
        GPU["GPU<br/>Many tasks in parallel<br/>High throughput"]
    end
  • Latency-sensitive: Web requests, interactive applications, databases
  • Throughput-sensitive: Batch processing, ML training, rendering

Key Concepts

The Performance Equation

CPU Time = Instruction Count × CPI × Clock Period
         = Instruction Count × CPI / Clock Rate

Amdahl’s Law

Speedup = 1 / ((1 - P) + P / N)

Limits the benefit of parallelization based on the sequential fraction.

Performance Counters

Hardware counters that measure:

  • Instructions executed
  • Cache misses
  • Branch mispredictions
  • Memory bandwidth utilization

Cross-References

Cross References