forked from rails/rails
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request rails#26792 from rails/benchmark-template
Introduce a benchmark template
- Loading branch information
Showing
2 changed files
with
67 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
begin | ||
require "bundler/inline" | ||
rescue LoadError => e | ||
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler" | ||
raise e | ||
end | ||
|
||
gemfile(true) do | ||
source "https://rubygems.org" | ||
gem "rails", github: "rails/rails" | ||
gem "benchmark-ips" | ||
end | ||
|
||
require "active_support" | ||
require "active_support/core_ext/object/blank" | ||
|
||
# Your patch goes here. | ||
class String | ||
def fast_blank? | ||
true | ||
end | ||
end | ||
|
||
# Enumerate some representative scenarios here. | ||
# | ||
# It is very easy to make an optimization that improves performance for a | ||
# specific scenario you care about but regresses on other common cases. | ||
# Therefore, you should test your change against a list of representative | ||
# scenarios. Ideally, they should be based on real-world scenarios extracted | ||
# from production applications. | ||
SCENARIOS = { | ||
"Empty" => "", | ||
"Single Space" => " ", | ||
"Two Spaces" => " ", | ||
"Mixed Whitspaces" => " \t\r\n", | ||
"Very Long String" => " " * 100 | ||
} | ||
|
||
SCENARIOS.each_pair do |name, value| | ||
puts | ||
puts " #{name} ".center(80, "=") | ||
puts | ||
|
||
Benchmark.ips do |x| | ||
x.report('blank?') { value.blank? } | ||
x.report('fast_blank?') { value.fast_blank? } | ||
x.compare! | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters