Defect #43737 » bench_commonmark.rb
| 1 |
require 'benchmark' |
|---|---|
| 2 |
|
| 3 |
Setting.text_formatting = 'common_mark' |
| 4 |
Setting.cache_formatted_text = 0 |
| 5 |
|
| 6 |
text = <<~MD |
| 7 |
| a | b |
|
| 8 |
|---|---|
|
| 9 |
| 1 | 2 |
|
| 10 |
|
| 11 |
```ruby
|
| 12 |
def hello
|
| 13 |
puts 'hi'
|
| 14 |
end
|
| 15 |
```
|
| 16 |
MD
|
| 17 |
|
| 18 |
iter = (ENV['ITER'] || '20').to_i |
| 19 |
mult = (ENV['MULT'] || '5').to_i |
| 20 |
text = Array.new(mult, text).join("\n") |
| 21 |
|
| 22 |
puts "ruby=#{RUBY_VERSION} iter=#{iter} mult=#{mult}" |
| 23 |
puts "commonmarker=#{Gem.loaded_specs['commonmarker']&.version} loofah=#{Gem.loaded_specs['loofah']&.version} rouge=#{Gem.loaded_specs['rouge']&.version}" |
| 24 |
|
| 25 |
# Warm up to avoid measuring one-time initialization costs.
|
| 26 |
2.times { Redmine::WikiFormatting.to_html('common_mark', text) } |
| 27 |
|
| 28 |
full = Benchmark.realtime do |
| 29 |
iter.times { Redmine::WikiFormatting.to_html('common_mark', text) } |
| 30 |
end
|
| 31 |
|
| 32 |
puts "full_ms=#{(full*1000).round(2)} avg_full=#{((full/iter)*1000).round(2)}" |