diff options
author | Godfrey Chan <godfreykfc@gmail.com> | 2016-10-15 12:36:07 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-15 12:36:07 +0200 |
commit | 0bf90faddbb24a93f3aced0d904a9be6a29ee987 (patch) | |
tree | 2fc45870c6745532cfc29a96cd34c537ba962201 /guides/bug_report_templates | |
parent | 77ed6b782a16f16c3cea3107f6715324ce9fa10a (diff) | |
parent | f2f9b8868590bb4be8965583096862e29b9f83fb (diff) | |
download | rails-0bf90faddbb24a93f3aced0d904a9be6a29ee987.tar.gz rails-0bf90faddbb24a93f3aced0d904a9be6a29ee987.tar.bz2 rails-0bf90faddbb24a93f3aced0d904a9be6a29ee987.zip |
Merge pull request #26792 from rails/benchmark-template
Introduce a benchmark template
Diffstat (limited to 'guides/bug_report_templates')
-rw-r--r-- | guides/bug_report_templates/benchmark.rb | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/guides/bug_report_templates/benchmark.rb b/guides/bug_report_templates/benchmark.rb new file mode 100644 index 0000000000..ae51d7027f --- /dev/null +++ b/guides/bug_report_templates/benchmark.rb @@ -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 |