Sha256: ed8ae23cc43777d2399003c1dcd1b614f3daeb753aeab0422d01101d511d6171

Contents?: true

Size: 1.32 KB

Versions: 61

Compression:

Stored size: 1.32 KB

Contents

#!/usr/bin/env ruby -wW1

$: << '.'
$: << '../lib'

if __FILE__ == $0
  while (i = ARGV.index('-I'))
    x,path = ARGV.slice!(i, 2)
    $: << path
  end
end

require 'optparse'
require 'stringio'
require 'multi_xml'

begin
  require 'libxml'
rescue Exception => e
end
begin
  require 'nokogiri'
rescue Exception => e
end
begin
  require 'ox'
rescue Exception => e
end

$verbose = 0
$parsers = []
$iter = 10

opts = OptionParser.new
opts.on("-v", "increase verbosity")                            { $verbose += 1 }
opts.on("-p", "--parser [String]", String, "parser to test")   { |p| $parsers = [p] }
opts.on("-i", "--iterations [Int]", Integer, "iterations")     { |i| $iter = i }
opts.on("-h", "--help", "Show this display")                   { puts opts; Process.exit!(0) }
files = opts.parse(ARGV)

if $parsers.empty?
  $parsers << 'libxml' if defined?(::LibXML)
  $parsers << 'nokogiri' if defined?(::Nokogiri)
  $parsers << 'ox' if defined?(::Ox)
end

files.each do |filename|
  times = { }
  xml = File.read(filename)
  $parsers.each do |p|
    MultiXml.parser = p
    start = Time.now
    $iter.times do |i|
      io = StringIO.new(xml)
      MultiXml.parse(io)
    end
    dt = Time.now - start
    times[p] = Time.now - start
  end
  times.each do |p,t|
    puts "%8s took %0.3f seconds to parse %s %d times." % [p, t, filename, $iter]
  end
end

Version data entries

61 entries across 60 versions & 9 rubygems

Version Path
plyom_user-0.2.4 vendor/bundle/ruby/2.0.0/gems/multi_xml-0.5.5/spec/speed.rb
plyom_user-0.2.3 vendor/bundle/ruby/2.0.0/gems/multi_xml-0.5.5/spec/speed.rb
plyom_user-0.2.2 vendor/bundle/ruby/2.0.0/gems/multi_xml-0.5.5/spec/speed.rb
plyom_user-0.2.1 vendor/bundle/ruby/2.0.0/gems/multi_xml-0.5.5/spec/speed.rb
plyom_user-0.2.0 vendor/bundle/ruby/2.0.0/gems/multi_xml-0.5.5/spec/speed.rb
plyom_user-0.1.9 vendor/bundle/ruby/2.0.0/gems/multi_xml-0.5.5/spec/speed.rb
plyom_user-0.1.8 vendor/bundle/ruby/2.0.0/gems/multi_xml-0.5.5/spec/speed.rb
plyom_user-0.1.7 vendor/bundle/ruby/2.0.0/gems/multi_xml-0.5.5/spec/speed.rb
plyom_user-0.1.6 vendor/bundle/ruby/2.0.0/gems/multi_xml-0.5.5/spec/speed.rb
plyom_user-0.1.5 vendor/bundle/ruby/2.0.0/gems/multi_xml-0.5.5/spec/speed.rb
plyom_user-0.1.4 vendor/bundle/ruby/2.0.0/gems/multi_xml-0.5.5/spec/speed.rb
plyom_user-0.1.3 vendor/bundle/ruby/2.0.0/gems/multi_xml-0.5.5/spec/speed.rb
plyom_user-0.1.2 vendor/bundle/ruby/2.0.0/gems/multi_xml-0.5.5/spec/speed.rb
plyom_user-0.1.1 vendor/bundle/ruby/2.0.0/gems/multi_xml-0.5.5/spec/speed.rb
plyom_user-0.1.0 vendor/bundle/ruby/2.0.0/gems/multi_xml-0.5.5/spec/speed.rb
plyom_user-0.0.9 vendor/bundle/ruby/2.0.0/gems/multi_xml-0.5.5/spec/speed.rb
plyom_user-0.0.8 vendor/bundle/ruby/2.0.0/gems/multi_xml-0.5.5/spec/speed.rb
plyom_user-0.0.7 vendor/bundle/ruby/2.0.0/gems/multi_xml-0.5.5/spec/speed.rb
plyom_user-0.0.6 vendor/bundle/ruby/2.0.0/gems/multi_xml-0.5.5/spec/speed.rb
plyom_user-0.0.5 vendor/bundle/ruby/2.0.0/gems/multi_xml-0.5.5/spec/speed.rb