Sha256: 525dc69d3a9a8fb6360fca24d1e716d180d8a348e1390ed9605658d0763b73b0

Contents?: true

Size: 908 Bytes

Versions: 4

Compression:

Stored size: 908 Bytes

Contents

# 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 'action_view'
require 'escape_utils'

class ActionPackBench
  extend ActionView::Helpers::JavaScriptHelper
end

times = 100
url = "http://code.jquery.com/jquery-1.4.2.js"
javascript = `curl -s #{url}`
puts "Escaping #{javascript.bytesize} bytes of javascript from #{url}"

puts ActionPackBench.escape_javascript(javascript).eql?(EscapeUtils.escape_javascript(javascript))

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

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
escape_utils-0.1.4 benchmark/javascript_escape.rb
escape_utils-0.1.3 benchmark/javascript_escape.rb
escape_utils-0.1.2 benchmark/javascript_escape.rb
escape_utils-0.1.1 benchmark/javascript_escape.rb