Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#render_html way slower than #render_doc.to_html #141

Closed
ojab opened this issue Jun 13, 2021 · 0 comments
Closed

#render_html way slower than #render_doc.to_html #141

ojab opened this issue Jun 13, 2021 · 0 comments
Labels

Comments

@ojab
Copy link
Contributor

ojab commented Jun 13, 2021

Not sure if it's commonmarker or underlying lib issue, but still.
Highly scientific benchmark

Benchmark.ips do |x|
  10.times do |n|
    x.report("commonmarker_render_html #{n}") do
      CommonMarker.render_html(text, :DEFAULT, [:autolink])
    end

    x.report("commonmarker_two_step #{n}") do
      parsed_doc = CommonMarker.render_doc(text, :DEFAULT, [:autolink])
      parsed_doc.to_html(:DEFAULT, [:autolink])
    end
  end

  x.compare!
end

where text is README.md from this repo shows

Comparison:
commonmarker_two_step 7:     6766.2 i/s
commonmarker_two_step 2:     6753.3 i/s - same-ish: difference falls within error
commonmarker_two_step 8:     6748.9 i/s - same-ish: difference falls within error
commonmarker_two_step 5:     6725.9 i/s - same-ish: difference falls within error
commonmarker_two_step 6:     6720.3 i/s - same-ish: difference falls within error
commonmarker_two_step 1:     6720.3 i/s - same-ish: difference falls within error
commonmarker_two_step 4:     6705.3 i/s - same-ish: difference falls within error
commonmarker_two_step 0:     6703.2 i/s - same-ish: difference falls within error
commonmarker_two_step 9:     6664.8 i/s - same-ish: difference falls within error
commonmarker_two_step 3:     6655.7 i/s - same-ish: difference falls within error
commonmarker_render_html 8:     2542.5 i/s - 2.66x  (± 0.00) slower
commonmarker_render_html 7:     2519.9 i/s - 2.69x  (± 0.00) slower
commonmarker_render_html 3:     2498.4 i/s - 2.71x  (± 0.00) slower
commonmarker_render_html 0:     2492.0 i/s - 2.72x  (± 0.00) slower
commonmarker_render_html 9:     2453.8 i/s - 2.76x  (± 0.00) slower
commonmarker_render_html 2:     2429.4 i/s - 2.79x  (± 0.00) slower
commonmarker_render_html 4:     2412.7 i/s - 2.80x  (± 0.00) slower
commonmarker_render_html 6:     2391.4 i/s - 2.83x  (± 0.00) slower
commonmarker_render_html 5:     2371.8 i/s - 2.85x  (± 0.00) slower
commonmarker_render_html 1:     2363.0 i/s - 2.86x  (± 0.00) slower

so we can easily speedup #render_html 2.5x times by using some more ruby, but I have a suspicion that it should be faster as is.

@gjtorikian gjtorikian added the bug label Jun 18, 2021
ojab added a commit to ojab/commonmarker that referenced this issue Feb 18, 2022
ojab added a commit to ojab/commonmarker that referenced this issue Feb 18, 2022
gjtorikian added a commit that referenced this issue Feb 25, 2022
Fixup benchmark and speedup a little, fixes #141
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants