Repository navigation
Refactoring code #169
Description
Activity
I found following code examples where we are not following the template
https://github.com/fastruby/fast-ruby/blob/main/code/enumerable/sort-vs-sort_by.rb - Here instead of faster and fastest, can we say fast and faster
https://github.com/fastruby/fast-ruby/blob/main/code/hash/keys-include-vs-key.rb - Can we change method name to slow and faster, as we are following same template for all our examples
https://github.com/fastruby/fast-ruby/blob/main/code/hash/values-include-vs-value.rb - Can we change method name to slow and faster, as we are following same template for all our examples
https://github.com/fastruby/fast-ruby/blob/main/code/method/call-vs-send-vs-method_missing.rb - Instead of fastest, rename to fast
https://github.com/fastruby/fast-ruby/blob/main/code/proc-and-block/proc-call-vs-yield.rb - can we rename slow1, slow2 etc to what actually that method is doing
https://github.com/fastruby/fast-ruby/blob/main/code/string/mutable_vs_immutable_strings.rb - specify which is slower and faster, as per the template we follow in all examples
https://github.com/fastruby/fast-ruby/blob/main/code/string/sub!-vs-gsub!-vs-%5B%5D%3D.rb - Can we change name from
slow_1to what method is egslow_subReacted by Aslan Dukaev and Juan Vásquez- linked a pull request that will close this issueName each benchmark's winner and lint it #243
on Sep 29, 2026 I noticed this too and worked on it, so that one glance at a file under
code/tells you which code isfastand which isslow.- Give every benchmark the same shape and lint it #242 gave every benchmark the same shape: default timing,
x.compare!at the end, and aBenchmark.ipsthat actually runs. - Name each benchmark's winner and lint it #243 named every report by rank. The recommended side uses
fast, thenfaster, thenfastest. The other side usesslow, thenslower, thenslowest. The winner is listed first. Names likeslow1,slow_1toslow_5,key_fastandwith_feezeare gone, including every file listed in Refactoring code #169 (comment).
@dukaev proposed this first in #170, putting the fast code first in 21 files. #243 finishes that idea.
The repo now has a linter that enforces the template, so new benchmarks can't drift from it. It fails CI when a
Benchmark.ipsblock doesn't callx.compare!, sets its own timing, never runs, or doesn't put exactly onefastest/faster/fastreport first:- Linter:
fast-ruby/.github/scripts/lint-benchmarks.rb
Lines 1 to 12 in 86836b0
# Checks that every benchmark under code/ has the same shape, so they all run, # print a comparison, and are measured the same way: # # - every Benchmark.ips block calls x.compare! # - no custom timing (Benchmark.ips(20), x.time = 20, x.warmup = 5, x.config(time: 20) in any hash syntax), # so every file uses the default # - no Benchmark.ips sits inside a method that never runs from the top of the file, # which would benchmark nothing at all # - every Benchmark.ips block states which report should win: exactly one # report calls `fastest` (else `faster`, else `fast`), and it comes first # # Usage: ruby .github/scripts/lint-benchmarks.rb [files...] (needs Ruby 3.3+) - CI job:
fast-ruby/.github/workflows/benchmarks.yml
Lines 27 to 35 in 86836b0
# Every benchmark has the same shape (see lint-benchmarks.rb). Reads the # files without running them, on the newest Ruby: the lint needs Prism. lint: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - name: Lint benchmarks run: docker compose run --rm -T --entrypoint ruby ruby_4.0 .github/scripts/lint-benchmarks.rb - Passing run on
main: https://github.com/fastruby/fast-ruby/actions/runs/36504571544/job/109202974677 - Naming rules for contributors:
Lines 47 to 50 in 86836b0
Name them by rank and list the winner first. The names grow outward from the line between fast and slow: the recommended side uses `fast`, then `faster`, then `fastest`; the other side uses `slow`, then `slower`, then `slowest`. The names are relative: `slow` only means slower than `fast`. When a ranking could look odd, say why in one line, like in `code/array/length-vs-size-vs-count.rb`:
Closing this one. Thanks for raising it!
- Give every benchmark the same shape and lint it #242 gave every benchmark the same shape: default timing,
- linked a pull request that will close this issueGive every benchmark the same shape and lint it #242
on Sep 29, 2026
I noticed that many examples in
code/do not match the template.