Practical guide to benchmarking your optimizations
summary
Argues that slowness usually comes from unbenchmarked design choices and shows concrete fixes: use Ruby’s Benchmark module (BMBM) with a rehearsal run, instrument with simple start_time checks, and pick representative data via stratified/cluster/systematic sampling; sample sizes around 100–500 (the statistical rule 384.5 gives ~95% confidence). Demonstrated a cat‑shelter estimator where a recursive black‑cat branch is the bottleneck, and a triangle‑sum problem replaced nested construction with a direct formula yielding orders‑of‑magnitude speedup.
AI-written summary · about
chapters (26)
- 0:00Intro
- 1:08Myth
- 1:57Why should you worry about performance?
- 2:42Moral of the story
- 4:51Let's dive into code!
- 6:32How fast is this code?
- 6:49Benchmarking
- 8:10Different types of samples
- 8:27Simple Random Sample
- 9:09Stratified Sample
- 10:29Cluster Sampling
- 11:12Systematic Random Sampling
- 11:43Multi-stage
- 12:16What should you use?
- 13:36Variables to consider
- 15:07Benchmark explained
- 16:58Example
- 19:10Things to watch out for
- 20:35What made black cats slower?
- 21:59Rethink the problem
- 23:35My solution...
- 24:20Better solution
- 25:01Performance difference?
- 25:23Find bottlenecks
- 27:23When should you benchmark changes?
- 28:41Go forth and benchmark!








