1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/guides/bug_report_templates/benchmark.rb
Robin Dupret f1e4d3d8dd Update bug report templates
Given that Bundler 1.10 was released back in 2015, we can assume
that people are at least on this version or a higher one so there
is no need to ask people to upgrade.

Also, given that Rails 5.0 supports Ruby 2.2+ and given that this
version come with Minitest 5.4.3 bundled, we don't need to ensure
backward compatibility with Minitest 4.
2018-10-28 18:12:48 +01:00

49 lines
1.1 KiB
Ruby

# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
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