CAComputer Architecture · Lesson 6 of 7
Thinking in Nanoseconds
Great engineers carry a mental price list for operations. Once you know a RAM access costs ~100ns and a disk read ~100µs, whole categories of design decisions become obvious.
Read the table vertically and rules of thumb fall out. Sequential beats random at every level. Memory beats disk by ~100x, disk beats network round trips. One database query per item in a loop (the N+1 problem) is catastrophic not because queries are slow, but because each one is a network round trip — half a million nanoseconds of waiting per item.
✦ Tip
Measure before optimizing — profilers (perf on Linux, Instruments on macOS) show where time actually goes, and it's rarely where you'd guess. But knowing the price list tells you what's plausible: if your code reads 1 GB from SSD, anything under ~2 seconds means caching is helping; anything over 30 means you're doing random reads.
Measure before optimizing — profilers (perf on Linux, Instruments on macOS) show where time actually goes, and it's rarely where you'd guess. But knowing the price list tells you what's plausible: if your code reads 1 GB from SSD, anything under ~2 seconds means caching is helping; anything over 30 means you're doing random reads.