File: benchmark.rb

package info (click to toggle)
ruby-commonmarker 0.23.10-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,456 kB
  • sloc: ansic: 10,575; ruby: 1,741; sh: 36; makefile: 22
file content (39 lines) | stat: -rw-r--r-- 1,010 bytes parent folder | download | duplicates (2)
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