Skip to content

Refactoring by template - #170

Closed
dukaev wants to merge 1 commit into
fastruby:mainfrom
dukaev:refactoring-position-slow-fast
Closed

dukaev wants to merge 1 commit into
fastruby:mainfrom
dukaev:refactoring-position-slow-fast

Conversation

@dukaev

@dukaev dukaev commented Feb 13, 2019 •

Copy link
Copy Markdown

require "benchmark/ips"

def fast
end

def slow
end

Benchmark.ips do |x|
  x.report("fast code description") { fast }
  x.report("slow code description") { slow }
  x.compare!
end
@dukaev dukaev changed the title Did refactoring by template Refactoring by template Feb 13, 2019

@mateusdeap mateusdeap left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dukaev I don't know if you're already on this, but I believe that if you just add Ashwini's suggestions to your PR, in the issue this solves, we can merge it.

Thanks for the good work!

@mateusdeap

Copy link
Copy Markdown
Contributor

If not, that's fine. Just let me know and I can take it over.

@dukaev

dukaev commented Oct 15, 2022

Copy link
Copy Markdown
Author

@mateusdeap great. In a few days I will do this

@JuanVqz JuanVqz linked an issue Sep 29, 2026 that may be closed by this pull request
@JuanVqz

JuanVqz commented Sep 29, 2026

Copy link
Copy Markdown
Member

Thanks @dukaev, and sorry this sat for so long. You spotted this in 2019: the fast code should come first so the template is easy to read at a glance.

It has now landed on main through #242 and #243. Those go a step further: every report is named by rank (fastest/faster/fast, then slow/slower/slowest) with the winner first, and a CI linter enforces it:

# 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+)

All 21 files you touched now follow that order, so I'm closing this one as superseded. Thanks for pushing on it early!

@JuanVqz JuanVqz closed this Sep 29, 2026
@JuanVqz JuanVqz mentioned this pull request Sep 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactoring code

3 participants