16.6. Measuring Performance

I don’t like to place too much emphasis on optimizing for speed. The best way to do this in general is to select a reasonable algorithm and use common sense.

Certainly speed matters. In some cases it matters greatly. But it is usually a mistake to worry about speed too soon in the development cycle. The saying goes, “Premature optimization is the root of all evil.” (This originated with Hoare and was restated by Knuth.) Or as someone else put it: “Make it right, then make it fast.” At the application level, this is generally a good heuristic (though at the level of large systems, it may be of less value).

I would add to this precept: Don’t optimize until you measure.

That isn’t so much to ask. Refrain from refactoring ...

Get The Ruby Way: Solutions and Techniques in Ruby Programming, Second Edition 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.