-
-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix benchmark, switch it to
benchmark-ips
and add xml + Node#to_html
- Loading branch information
Showing
2 changed files
with
26 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ source 'https://rubygems.org/' | |
gemspec | ||
|
||
group :benchmark do | ||
gem 'benchmark-ips' | ||
gem 'kramdown' | ||
gem 'redcarpet' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |