Skip to content

Commit

Permalink
move benchmarks to benchmark-ips
Browse files Browse the repository at this point in the history
  • Loading branch information
brianmario committed Mar 25, 2015
1 parent d55bf9c commit ea2b65b
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 77 deletions.
26 changes: 13 additions & 13 deletions benchmark/html_escape.rb
@@ -1,9 +1,8 @@
# encoding: utf-8
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/..')
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')

require 'rubygems'
require 'benchmark'
require 'bundler/setup'
require 'benchmark/ips'

require 'rack'
require 'erb'
Expand All @@ -16,53 +15,54 @@ module HamlBench
extend Haml::Helpers
end

times = 100
url = "http://en.wikipedia.org/wiki/Line_of_succession_to_the_British_throne"
html = `curl -s #{url}`
html = html.force_encoding('utf-8') if html.respond_to?(:force_encoding)
puts "Escaping #{html.bytesize} bytes of html #{times} times, from #{url}"
puts "Escaping #{html.bytesize} bytes of html from #{url}"

Benchmark.bmbm do |x|
x.report "Rack::Utils.escape_html" do
Benchmark.ips do |x|
x.report "Rack::Utils.escape_html" do |times|
times.times do
Rack::Utils.escape_html(html)
end
end

x.report "Haml::Helpers.html_escape" do
x.report "Haml::Helpers.html_escape" do |times|
times.times do
HamlBench.html_escape(html)
end
end

x.report "ERB::Util.html_escape" do
x.report "ERB::Util.html_escape" do |times|
times.times do
ERB::Util.html_escape(html)
end
end

x.report "CGI.escapeHTML" do
x.report "CGI.escapeHTML" do |times|
times.times do
CGI.escapeHTML(html)
end
end

x.report "String#gsub" do
x.report "String#gsub" do |times|
html_escape = { '&' => '&amp;', '>' => '&gt;', '<' => '&lt;', '"' => '&quot;', "'" => '&#39;' }
times.times do
html.gsub(/[&"'><]/, html_escape)
end
end

x.report "fast_xs_extra#fast_xs_html" do
x.report "fast_xs_extra#fast_xs_html" do |times|
times.times do
html.fast_xs_html
end
end

x.report "EscapeUtils.escape_html" do
x.report "EscapeUtils.escape_html" do |times|
times.times do
EscapeUtils.escape_html(html)
end
end

x.compare!
end
18 changes: 9 additions & 9 deletions benchmark/html_unescape.rb
@@ -1,9 +1,8 @@
# encoding: utf-8
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/..')
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')

require 'rubygems'
require 'benchmark'
require 'bundler/setup'
require 'benchmark/ips'

require 'cgi'
require 'haml'
Expand All @@ -13,23 +12,24 @@ module HamlBench
extend Haml::Helpers
end

times = 100
url = "http://en.wikipedia.org/wiki/Line_of_succession_to_the_British_throne"
html = `curl -s #{url}`
html = html.force_encoding('binary') if html.respond_to?(:force_encoding)
escaped_html = EscapeUtils.escape_html(html)
puts "Unescaping #{escaped_html.bytesize} bytes of escaped html #{times} times, from #{url}"
puts "Unescaping #{escaped_html.bytesize} bytes of escaped html, from #{url}"

Benchmark.bmbm do |x|
x.report "CGI.unescapeHTML" do
Benchmark.ips do |x|
x.report "CGI.unescapeHTML" do |times|
times.times do
CGI.unescapeHTML(escaped_html)
end
end

x.report "EscapeUtils.unescape_html" do
x.report "EscapeUtils.unescape_html" do |times|
times.times do
EscapeUtils.unescape_html(escaped_html)
end
end
end

x.compare!
end
18 changes: 9 additions & 9 deletions benchmark/javascript_escape.rb
@@ -1,9 +1,8 @@
# encoding: utf-8
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/..')
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')

require 'rubygems'
require 'benchmark'
require 'bundler/setup'
require 'benchmark/ips'

require 'action_view'
require 'escape_utils'
Expand All @@ -12,22 +11,23 @@ class ActionPackBench
extend ActionView::Helpers::JavaScriptHelper
end

times = 100
url = "http://ajax.googleapis.com/ajax/libs/dojo/1.4.3/dojo/dojo.xd.js.uncompressed.js"
javascript = `curl -s #{url}`
javascript = javascript.force_encoding('utf-8') if javascript.respond_to?(:force_encoding)
puts "Escaping #{javascript.bytesize} bytes of javascript #{times} times, from #{url}"
puts "Escaping #{javascript.bytesize} bytes of javascript, from #{url}"

Benchmark.bmbm do |x|
x.report "ActionView::Helpers::JavaScriptHelper#escape_javascript" do
Benchmark.ips do |x|
x.report "ActionView::Helpers::JavaScriptHelper#escape_javascript" do |times|
times.times do
ActionPackBench.escape_javascript(javascript)
end
end

x.report "EscapeUtils.escape_javascript" do
x.report "EscapeUtils.escape_javascript" do |times|
times.times do
EscapeUtils.escape_javascript(javascript)
end
end
end

x.compare!
end
14 changes: 6 additions & 8 deletions benchmark/javascript_unescape.rb
@@ -1,23 +1,21 @@
# encoding: utf-8
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/..')
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')

require 'rubygems'
require 'benchmark'
require 'bundler/setup'
require 'benchmark/ips'

require 'escape_utils'

times = 100
url = "http://ajax.googleapis.com/ajax/libs/dojo/1.4.3/dojo/dojo.xd.js.uncompressed.js"
javascript = `curl -s #{url}`
javascript = javascript.force_encoding('utf-8') if javascript.respond_to?(:force_encoding)
escaped_javascript = EscapeUtils.escape_javascript(javascript)
puts "Escaping #{escaped_javascript.bytesize} bytes of javascript #{times} times, from #{url}"
puts "Escaping #{escaped_javascript.bytesize} bytes of javascript, from #{url}"

Benchmark.bmbm do |x|
x.report "EscapeUtils.escape_javascript" do
Benchmark.ips do |x|
x.report "EscapeUtils.escape_javascript" do |times|
times.times do
EscapeUtils.unescape_javascript(escaped_javascript)
end
end
end
end
26 changes: 13 additions & 13 deletions benchmark/url_escape.rb
@@ -1,9 +1,8 @@
# encoding: utf-8
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/..')
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')

require 'rubygems'
require 'benchmark'
require 'bundler/setup'
require 'benchmark/ips'

require 'rack'
require 'erb'
Expand All @@ -12,45 +11,46 @@
require 'fast_xs_extra'
require 'escape_utils'

times = 10_000
url = "https://www.yourmom.com/cgi-bin/session.cgi?sess_args=mYHcEA dh435dqUs0moGHeeAJTSLLbdbcbd9ef----,574b95600e9ab7d27eb0bf524ac68c27----"
url = url.force_encoding('us-ascii') if url.respond_to?(:force_encoding)
puts "Escaping a #{url.bytesize} byte URL #{times} times"
puts "Escaping a #{url.bytesize} byte URL times"

Benchmark.bmbm do |x|
x.report "ERB::Util.url_encode" do
Benchmark.ips do |x|
x.report "ERB::Util.url_encode" do |times|
times.times do
ERB::Util.url_encode(url)
end
end

x.report "Rack::Utils.escape" do
x.report "Rack::Utils.escape" do |times|
times.times do
Rack::Utils.escape(url)
end
end

x.report "CGI.escape" do
x.report "CGI.escape" do |times|
times.times do
CGI.escape(url)
end
end

x.report "URLEscape#escape" do
x.report "URLEscape#escape" do |times|
times.times do
URLEscape.escape(url)
end
end

x.report "fast_xs_extra#fast_xs_url" do
x.report "fast_xs_extra#fast_xs_url" do |times|
times.times do
url.fast_xs_url
end
end

x.report "EscapeUtils.escape_url" do
x.report "EscapeUtils.escape_url" do |times|
times.times do
EscapeUtils.escape_url(url)
end
end
end

x.compare!
end
28 changes: 14 additions & 14 deletions benchmark/url_unescape.rb
@@ -1,50 +1,50 @@
# encoding: utf-8
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/..')
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')

require 'rubygems'
require 'benchmark'
require 'bundler/setup'
require 'benchmark/ips'

require 'rack'
require 'cgi'
require 'url_escape'
require 'fast_xs_extra'
require 'escape_utils'

times = 10_000
url = "https://www.yourmom.com/cgi-bin/session.cgi?sess_args=mYHcEA dh435dqUs0moGHeeAJTSLLbdbcbd9ef----,574b95600e9ab7d27eb0bf524ac68c27----"
url = url.force_encoding('us-ascii') if url.respond_to?(:force_encoding)
escaped_url = EscapeUtils.escape_url(url)
puts "Escaping a #{url.bytesize} byte URL #{times} times"
puts "Escaping a #{url.bytesize} byte URL"

Benchmark.bmbm do |x|
x.report "Rack::Utils.unescape" do
Benchmark.ips do |x|
x.report "Rack::Utils.unescape" do |times|
times.times do
Rack::Utils.unescape(escaped_url)
end
end
x.report "CGI.unescape" do

x.report "CGI.unescape" do |times|
times.times do
CGI.unescape(escaped_url)
end
end
x.report "URLEscape#unescape" do

x.report "URLEscape#unescape" do |times|
times.times do
URLEscape.unescape(escaped_url)
end
end

x.report "fast_xs_extra#fast_uxs_cgi" do
x.report "fast_xs_extra#fast_uxs_cgi" do |times|
times.times do
url.fast_uxs_cgi
end
end

x.report "EscapeUtils.unescape_url" do
x.report "EscapeUtils.unescape_url" do |times|
times.times do
EscapeUtils.unescape_url(escaped_url)
end
end
end

x.compare!
end
20 changes: 10 additions & 10 deletions benchmark/xml_escape.rb
@@ -1,29 +1,29 @@
# encoding: utf-8
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/..')
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')

require 'rubygems'
require 'benchmark'
require 'bundler/setup'
require 'benchmark/ips'

require 'builder'
require 'fast_xs'
require 'escape_utils'

times = 100
url = "http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml"
xml = `curl -s #{url}`
xml = xml.force_encoding('binary') if xml.respond_to?(:force_encoding)
puts "Escaping #{xml.bytesize} bytes of xml #{times} times, from #{url}"
puts "Escaping #{xml.bytesize} bytes of xml, from #{url}"

Benchmark.bmbm do |x|
x.report "Builder::String.to_xs" do
Benchmark.ips do |x|
x.report "fast_xs" do |times|
times.times do
xml.to_xs
xml.fast_xs
end
end

x.report "EscapeUtils.escape_xml" do
x.report "EscapeUtils.escape_xml" do |times|
times.times do
EscapeUtils.escape_xml(xml)
end
end

x.compare!
end
2 changes: 1 addition & 1 deletion escape_utils.gemspec
Expand Up @@ -22,10 +22,10 @@ Gem::Specification.new do |s|
s.add_development_dependency 'rake-compiler', ">= 0.7.5"
s.add_development_dependency 'minitest', ">= 5.0.0"
# benchmarks
s.add_development_dependency 'benchmark-ips'
s.add_development_dependency 'rack'
s.add_development_dependency 'haml'
s.add_development_dependency 'fast_xs'
s.add_development_dependency 'actionpack'
s.add_development_dependency 'url_escape'
end

0 comments on commit ea2b65b

Please sign in to comment.