Optimize but Don’t Break

We’ll start our profiling session by writing a test and a benchmark. Why? Because optimization means making changes to the code, most often to its core part. Sometimes, optimization requires complex architectural changes. And we should be able to make substantial changes without fearing we’ll break things. This is why we need the test. We’ll use the test to make sure we didn’t break anything during optimization. Benchmarking is important because, as you’ll see later, the speedup in the profiler won’t always translate to the same improvement in the real world. So we need to measure our code’s performance before and after optimization to ensure that things got faster.

We’ll embed the test directly into the application ...

Get Ruby Performance Optimization now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.