File: xml_escape.rb

package info (click to toggle)
ruby-escape-utils 1.0.1-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 348 kB
  • ctags: 248
  • sloc: ansic: 1,718; ruby: 924; makefile: 2
file content (29 lines) | stat: -rw-r--r-- 712 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
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 'builder'
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}"

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

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