Sha256: 9540302ad04844366b63d100229fa7dbc0a39c44be9607575c8d21e14629beae

Contents?: true

Size: 938 Bytes

Versions: 6

Compression:

Stored size: 938 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://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}"

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

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
escape_utils-1.0.1 benchmark/javascript_escape.rb
escape_utils-1.0.0 benchmark/javascript_escape.rb
escape_utils-0.3.2 benchmark/javascript_escape.rb
escape_utils-0.3.1 benchmark/javascript_escape.rb
escape_utils-0.3.0 benchmark/javascript_escape.rb
escape_utils-0.2.4 benchmark/javascript_escape.rb