Look up the faster of two equivalent Ruby idioms before writing performance-sensitive code
Run the fasterer companion tool on your own Ruby codebase to flag slow patterns automatically
Study the benchmark source files to learn how to write accurate microbenchmarks in Ruby
Contribute a new idiom comparison by adding a benchmark file and updating the README
Fast Ruby is a reference collection of Ruby coding patterns, each paired with a benchmark showing which version of the code runs faster. The project grew out of a 2014 conference talk about writing performant Ruby and has since been maintained as a living document that Ruby developers can consult when they want to make small, targeted speed improvements. The collection covers many categories of common Ruby operations: general language features, arrays, hashes, strings, dates, ranges, iterators, and more. For each pairing, the README shows two or more ways to accomplish the same thing in Ruby, runs them against a benchmarking tool, and reports how many times per second each version can execute. A typical entry might compare two methods of checking whether an object responds to a particular method, with one approach running several times faster than the other. The project is careful to note that these are not universal rules to apply without thinking. Some alternatives only apply in certain situations, and swapping one idiom for another without understanding the context can introduce bugs. The README treats each entry as guidance rather than a strict prescription. Benchmarks are run automatically via a continuous integration workflow on GitHub so that results stay current as the Ruby language evolves. The numbers shown in the README reflect a specific Ruby version and machine configuration, and results on other systems will differ. A companion static analysis tool called fasterer can scan your own codebase and flag places where the faster idioms from this collection could apply. The repository also contains the source code files for every benchmark, so anyone can run the comparisons locally or adapt them for their own testing. Contributions adding new idiom comparisons are welcome. The full README is longer than what was shown.
← fastruby on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.