Skip to content

Instantly share code, notes, and snippets.

@k0kubun
Created December 24, 2015 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save k0kubun/8e1c7efb1e29991e1382 to your computer and use it in GitHub Desktop.
Save k0kubun/8e1c7efb1e29991e1382 to your computer and use it in GitHub Desktop.
require 'benchmark/ips'
require 'cgi'
str = ARGV.first
puts "Escape: #{str}"
Benchmark.ips do |x|
def old_escapeHTML(string)
string.gsub(/['&\"<>]/, CGI::Util::TABLE_FOR_ESCAPE_HTML__)
end
x.report("before") { old_escapeHTML(str) }
x.report("after") { CGI.escapeHTML(str) }
x.compare!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment