Skip to content

Commit

Permalink
Add updated benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
gjtorikian committed Jan 30, 2024
1 parent 7ce8b59 commit 0224ec8
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 20 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ end

group :benchmark do
gem "benchmark-ips"
gem "markly"
gem "kramdown"
gem "kramdown-parser-gfm"
gem "redcarpet"
Expand Down
36 changes: 21 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -281,26 +281,32 @@ If there were no errors, you're done! Otherwise, make sure to follow the comrak

## Benchmarks

Some rough benchmarks:

```
$ bundle exec rake benchmark
❯ bundle exec rake benchmark
input size = 11064832 bytes
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin23]
Warming up --------------------------------------
redcarpet 2.000 i/100ms
commonmarker with to_html
1.000 i/100ms
kramdown 1.000 i/100ms
Markly.render_html 1.000 i/100ms
Markly::Node#to_html 1.000 i/100ms
Commonmarker.to_html 1.000 i/100ms
Commonmarker::Node.to_html
1.000 i/100ms
Kramdown::Document#to_html
1.000 i/100ms
Calculating -------------------------------------
redcarpet 22.317 (± 4.5%) i/s - 112.000 in 5.036374s
commonmarker with to_html
5.815 (± 0.0%) i/s - 30.000 in 5.168869s
kramdown 0.327 (± 0.0%) i/s - 2.000 in 6.121486s
Markly.render_html 15.606 (±25.6%) i/s - 71.000 in 5.047132s
Markly::Node#to_html 15.692 (±25.5%) i/s - 72.000 in 5.095810s
Commonmarker.to_html 4.482 (± 0.0%) i/s - 23.000 in 5.137680s
Commonmarker::Node.to_html
5.092 (±19.6%) i/s - 25.000 in 5.072220s
Kramdown::Document#to_html
0.379 (± 0.0%) i/s - 2.000 in 5.277770s
Comparison:
redcarpet: 22.3 i/s
commonmarker with to_html: 5.8 i/s - 3.84x (± 0.00) slower
kramdown: 0.3 i/s - 68.30x (± 0.00) slower
Markly::Node#to_html: 15.7 i/s
Markly.render_html: 15.6 i/s - same-ish: difference falls within error
Commonmarker::Node.to_html: 5.1 i/s - 3.08x slower
Commonmarker.to_html: 4.5 i/s - 3.50x slower
Kramdown::Document#to_html: 0.4 i/s - 41.40x slower
```
24 changes: 19 additions & 5 deletions test/benchmark.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,39 @@

require "benchmark/ips"
require "commonmarker"
require "redcarpet"
require "markly"
require "kramdown"
require "kramdown-parser-gfm"
require "redcarpet"
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: true, tables: true, strikethrough: true, footnotes: true).render(benchinput)
x.report("Markly.render_html") do
Markly.render_html(benchinput)
end

x.report("Markly::Node#to_html") do
Markly.parse(benchinput).to_html
end

x.report("commonmarker with to_html") do
# Redcarpet is faster, but does not support true commonmarker syntax
# x.report("Redcarpet::Markdown#render") do
# Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true, tables: true, strikethrough: true, footnotes: true).render(benchinput)
# end

x.report("Commonmarker.to_html") do
Commonmarker.to_html(benchinput)
end

x.report("kramdown") do
x.report("Commonmarker::Node.to_html") do
Commonmarker.parse(benchinput).to_html
end

x.report("Kramdown::Document#to_html") do
Kramdown::Document.new(benchinput, input: "GFM").to_html
end

Expand Down

0 comments on commit 0224ec8

Please sign in to comment.