mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Improve HTML escape benchmarks
This commit is contained in:
parent
dd4ae9a475
commit
f276d5a7fe
2 changed files with 45 additions and 23 deletions
|
@ -1,32 +1,23 @@
|
|||
prelude: require 'cgi/escape'
|
||||
prelude: |
|
||||
# frozen_string_literal: true
|
||||
require 'cgi/escape'
|
||||
benchmark:
|
||||
- name: escape_html_blank
|
||||
prelude: str = ""
|
||||
script: CGI.escapeHTML(str)
|
||||
- script: CGI.escapeHTML("")
|
||||
loop_count: 20000000
|
||||
- name: escape_html_short_none
|
||||
prelude: str = "abcde"
|
||||
script: CGI.escapeHTML(str)
|
||||
- script: CGI.escapeHTML("abcde")
|
||||
loop_count: 20000000
|
||||
- name: escape_html_short_one
|
||||
prelude: str = "abcd<"
|
||||
script: CGI.escapeHTML(str)
|
||||
- script: CGI.escapeHTML("abcd<")
|
||||
loop_count: 20000000
|
||||
- name: escape_html_short_all
|
||||
prelude: str = "'&\"<>"
|
||||
script: CGI.escapeHTML(str)
|
||||
- script: CGI.escapeHTML("'&\"<>")
|
||||
loop_count: 5000000
|
||||
- name: escape_html_long_none
|
||||
prelude: str = "abcde" * 300
|
||||
script: CGI.escapeHTML(str)
|
||||
- prelude: long_no_escape = "abcde" * 300
|
||||
script: CGI.escapeHTML(long_no_escape)
|
||||
loop_count: 1000000
|
||||
- name: escape_html_long_all
|
||||
prelude: str = "'&\"<>" * 10
|
||||
script: CGI.escapeHTML(str)
|
||||
- prelude: long_all_escape = "'&\"<>" * 10
|
||||
script: CGI.escapeHTML(long_all_escape)
|
||||
loop_count: 1000000
|
||||
- name: escape_html_real
|
||||
prelude: | # http://example.com/
|
||||
str = <<~HTML
|
||||
- prelude: | # http://example.com/
|
||||
example_html = <<~HTML
|
||||
<body>
|
||||
<div>
|
||||
<h1>Example Domain</h1>
|
||||
|
@ -36,5 +27,5 @@ benchmark:
|
|||
</div>
|
||||
</body>
|
||||
HTML
|
||||
script: CGI.escapeHTML(str)
|
||||
script: CGI.escapeHTML(example_html)
|
||||
loop_count: 1000000
|
||||
|
|
31
benchmark/erb_escape_html.yml
Normal file
31
benchmark/erb_escape_html.yml
Normal file
|
@ -0,0 +1,31 @@
|
|||
prelude: |
|
||||
# frozen_string_literal: true
|
||||
require 'erb'
|
||||
benchmark:
|
||||
- script: ERB::Util.html_escape("")
|
||||
loop_count: 20000000
|
||||
- script: ERB::Util.html_escape("abcde")
|
||||
loop_count: 20000000
|
||||
- script: ERB::Util.html_escape("abcd<")
|
||||
loop_count: 20000000
|
||||
- script: ERB::Util.html_escape("'&\"<>")
|
||||
loop_count: 5000000
|
||||
- prelude: long_no_escape = "abcde" * 300
|
||||
script: ERB::Util.html_escape(long_no_escape)
|
||||
loop_count: 1000000
|
||||
- prelude: long_all_escape = "'&\"<>" * 10
|
||||
script: ERB::Util.html_escape(long_all_escape)
|
||||
loop_count: 1000000
|
||||
- prelude: | # http://example.com/
|
||||
example_html = <<~HTML
|
||||
<body>
|
||||
<div>
|
||||
<h1>Example Domain</h1>
|
||||
<p>This domain is established to be used for illustrative examples in documents. You may use this
|
||||
domain in examples without prior coordination or asking for permission.</p>
|
||||
<p><a href="http://www.iana.org/domains/example">More information...</a></p>
|
||||
</div>
|
||||
</body>
|
||||
HTML
|
||||
script: ERB::Util.html_escape(example_html)
|
||||
loop_count: 1000000
|
Loading…
Reference in a new issue