Skip to content

Commit

Permalink
Fix benchmark, switch it to benchmark-ips and add xml + Node#to_html
Browse files Browse the repository at this point in the history
  • Loading branch information
ojab committed Feb 18, 2022
1 parent f30f525 commit 1ee03a8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ source 'https://rubygems.org/'
gemspec

group :benchmark do
gem 'benchmark-ips'
gem 'kramdown'
gem 'redcarpet'
end
43 changes: 25 additions & 18 deletions test/benchmark.rb
Original file line number Diff line number Diff line change
@@ -1,32 +1,39 @@
# frozen_string_literal: true

require 'benchmark/ips'
require 'commonmarker'
require 'github/markdown'
require 'redcarpet'
require 'kramdown'
require 'benchmark'

def dobench(name, &blk)
puts name
puts Benchmark.measure(&blk)
end
benchinput = File.read('test/benchinput.md').freeze

benchinput = File.open('test/benchinput.md', 'r').read
printf("input size = %<bytes>d bytes\n\n", {bytes: benchinput.bytesize})

printf("input size = %<bytes>d bytes\n\n", benchinput.bytesize)
Benchmark.ips do |x|
x.report('redcarpet') do
Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: false, tables: false).render(benchinput)
end

dobench('redcarpet') do
Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: false, tables: false).render(benchinput)
end
x.report('commonmarker with to_html') do
CommonMarker.render_html(benchinput)
end

dobench('commonmarker with to_html') do
CommonMarker.render_html(benchinput)
end
x.report('commonmarker with to_xml') do
CommonMarker.render_html(benchinput)
end

dobench('commonmarker with ruby HtmlRenderer') do
CommonMarker::HtmlRenderer.new.render(CommonMarker.render_doc(benchinput))
end
x.report('commonmarker with ruby HtmlRenderer') do
CommonMarker::HtmlRenderer.new.render(CommonMarker.render_doc(benchinput))
end

x.report('commonmarker with render_doc.to_html') do
CommonMarker.render_doc(benchinput, :DEFAULT, [:autolink]).to_html(:DEFAULT, [:autolink])
end

x.report('kramdown') do
Kramdown::Document.new(benchinput).to_html(benchinput)
end

dobench('kramdown') do
Kramdown::Document.new(benchinput).to_html(benchinput)
x.compare!
end

0 comments on commit 1ee03a8

Please sign in to comment.