What is actually inside the box?
Almost every real performance question an engineer faces — "why is my app slow?", "why did unsaved work disappear?", "why does the server fall over when it runs out of memory?" — comes down to which physical part of the computer the data is sitting in. So this course starts with the parts.
Every computer you have ever used, from a laptop to a phone to a server in a data center, is built from the same three physical parts:
- The CPU (central processing unit) executes instructions — tiny steps like "add these two numbers" or "copy this value" — billions of times per second. It is the only part that actually computes anything.
- RAM (random access memory) holds the data and programs the CPU is working on right now, because the CPU can only keep up its speed on data it can reach in nanoseconds. RAM is fast, but it loses everything the instant power is cut. If a picture helps: it is the desk you spread your work out on.
- The disk (an SSD or hard drive) keeps files permanently, even with the power off, because it stores data in a physical form that does not need electricity to persist — but reading it is much slower than RAM. It is the filing cabinet next to that desk.
Everything your code does maps onto these three parts.
Why three parts and not one?
Because speed and permanence pull in opposite directions. Fast memory is expensive and loses data without power. Cheap, permanent storage is slow. So computers use a hierarchy: a tiny amount of very fast memory close to the CPU, a medium amount of RAM, and a huge, slow disk.
Rough numbers to keep in your head:
| Part | Typical size | Read time |
|---|---|---|
| CPU cache | megabytes | ~1 nanosecond |
| RAM | gigabytes | ~100 nanoseconds |
| SSD | terabytes | ~100,000 nanoseconds |
A nanosecond is a billionth of a second. The exact numbers vary by machine, but the ratios are what matter: the disk is roughly a thousand times slower than RAM. Run the numbers yourself below.
Code exercise · python
Run this program. It compares a typical RAM read to a typical SSD read using integer division (the // operator gives a whole number).
Code exercise · python
Your turn. Using the table above (cache ≈ 1 ns, RAM ≈ 100 ns, SSD ≈ 100,000 ns), print the three speed ratios with integer division (//). Match the expected output exactly.
Quiz
You are editing a document and the power suddenly cuts out. The unsaved changes are gone, but the file you saved an hour ago is fine. Why?
Problem
One of the three parts is often called "volatile" because it loses its contents the instant power is cut. Which part is it? (one word)