Sha256: a6fdc05a8463e7447c5fda585da3a655706bb8a312e887fa0cd7c5ea1ade477f

Contents?: true

Size: 786 Bytes

Versions: 1

Compression:

Stored size: 786 Bytes

Contents

# encoding: utf-8

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

require 'action_view'
require 'escape_utils'

class ActionPackBench
  extend ActionView::Helpers::JavaScriptHelper
end

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')
puts "Escaping #{javascript.bytesize} bytes of javascript, from #{url}"

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 |times|
    times.times do
      EscapeUtils.escape_javascript(javascript)
    end
  end

  x.compare!
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
escape_utils-1.3.0 benchmark/javascript_escape.rb