2017-08-13 09:02:48 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-10-28 13:12:48 -04:00
|
|
|
require "bundler/inline"
|
2016-10-15 06:27:18 -04:00
|
|
|
|
|
|
|
gemfile(true) do
|
|
|
|
source "https://rubygems.org"
|
2017-09-27 04:55:43 -04:00
|
|
|
|
2017-09-26 17:02:11 -04:00
|
|
|
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
|
2017-09-27 04:55:43 -04:00
|
|
|
|
2016-10-15 06:27:18 -04:00
|
|
|
gem "rails", github: "rails/rails"
|
2020-06-04 21:17:51 -04:00
|
|
|
gem "benchmark-ips"
|
2016-10-15 06:27:18 -04:00
|
|
|
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|
|
2016-10-28 23:05:58 -04:00
|
|
|
x.report("blank?") { value.blank? }
|
|
|
|
x.report("fast_blank?") { value.fast_blank? }
|
2016-10-15 06:27:18 -04:00
|
|
|
x.compare!
|
|
|
|
end
|
|
|
|
end
|