diff --git a/Gemfile.lock b/Gemfile.lock index 14f51dd..664ee70 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -8,6 +8,7 @@ GEM remote: https://rubygems.org/ specs: ast (2.4.3) + benchmark-ips (2.15.1) bundler-audit (0.9.3) bundler (>= 1.2.0) thor (~> 1.0) @@ -82,6 +83,7 @@ PLATFORMS x86_64-linux DEPENDENCIES + benchmark-ips bundler-audit colorize html2text! diff --git a/bench/convert.rb b/bench/convert.rb new file mode 100644 index 0000000..d96cc73 --- /dev/null +++ b/bench/convert.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +# Usage: bundle exec ruby bench/convert.rb +# +# Compare branches by running it on each. The sibling divs case guards against +# the quadratic slowdown fixed in #45. + +require 'benchmark/ips' +require_relative '../lib/html2text' + +examples = Dir[File.join(__dir__, '../spec/examples/*.html')].map { |f| File.read(f) } +sibling_divs = "
#{'
x
' * 2000}
" + +Benchmark.ips do |x| + x.report('all spec examples') { examples.each { |html| Html2Text.convert(html) } } + x.report('2000 sibling divs') { Html2Text.convert(sibling_divs) } +end diff --git a/html2text.gemspec b/html2text.gemspec index 2e122eb..be61fac 100644 --- a/html2text.gemspec +++ b/html2text.gemspec @@ -21,6 +21,7 @@ Gem::Specification.new do |s| s.add_dependency 'nokogiri', ['>= 1.0', '< 2.0'] + s.add_development_dependency 'benchmark-ips' s.add_development_dependency 'bundler-audit' s.add_development_dependency 'colorize' s.add_development_dependency 'rake'