1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
# frozen_string_literal: true
require "benchmark/ips"
require "commonmarker"
require "redcarpet"
require "kramdown"
require "benchmark"
benchinput = File.read("test/benchinput.md").freeze
printf("input size = %<bytes>d bytes\n\n", { bytes: benchinput.bytesize })
Benchmark.ips do |x|
x.report("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
x.report("commonmarker with to_xml") do
CommonMarker.render_html(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
x.compare!
end
|