Sha256: 4d271a2b68d673cdcaa544b05b1be77d52c3bdc7729c407fb422f5aa2a164854

Contents?: true

Size: 1.64 KB

Versions: 40

Compression:

Stored size: 1.64 KB

Contents

#!/usr/bin/env ruby -wW1

$: << '.'

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

require 'optparse'
require 'pp'
require 'nokogiri'
require 'ox'

ox_only = false
it = 1000

opts = OptionParser.new
opts.on("-x", "ox only")                                      { ox_only = true }
opts.on("-i", "--iterations [Int]", Integer, "iterations")    { |i| it = i }
opts.on("-h", "--help", "Show this display")                  { puts opts }
files = opts.parse(ARGV)

obj = nil

puts "to String and writing #{files}\n\n"

data = files.map do |f|
  ox_obj = Ox.parse_file(f)
  xml = File.read(f)
  no_obj = Nokogiri::XML::Document.parse(xml, nil, nil, Nokogiri::XML::ParseOptions::DEFAULT_XML | Nokogiri::XML::ParseOptions::NOBLANKS)
  [f, ox_obj, no_obj]
end

start = Time.now
data.each do |d|
  (1..it).each do
    xml = d[1].to_s
  end
end
ox_time = Time.now - start
puts "to String #{it} times with ox took #{ox_time} seconds."

#puts obj.to_s

=begin
start = Time.now
data.each do |d|
  (1..it).each do
    xml = d[1].to_s
  end
end
ox_time = Time.now - start
puts "to file #{it} times with ox took #{ox_time} seconds.\n\n"
=end
if !ox_only

  start = Time.now
  data.each do |d|
    (1..it).each do
      xml = d[2].to_s
    end
  end
  no_time = Time.now - start
  puts "to String #{it} times with nokogiri took #{no_time} seconds."
=begin
  start = Time.now
  data.each do |d|
    xml = d[1]
    (1..it).each do
      xml = d[2].to_s
    end
  end
  no_time = Time.now - start
  puts "to file #{it} times with nokogiri took #{no_time} seconds.\n\n"
=end
  puts "Ox is %0.1f faster than Nokogiri" % [no_time/ox_time]
end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
ox-1.5.4 test/perf_write.rb
ox-1.5.3 test/perf_write.rb
ox-1.5.2 test/perf_write.rb
ox-1.5.1 test/perf_write.rb
ox-1.5.0 test/perf_write.rb
ox-1.4.6 test/perf_write.rb
ox-1.4.5 test/perf_write.rb
ox-1.4.4 test/perf_write.rb
ox-1.4.3 test/perf_write.rb
ox-1.4.2 test/perf_write.rb
ox-1.4.1 test/perf_write.rb
ox-1.4.0 test/perf_write.rb
ox-1.3.5 test/perf_write.rb
ox-1.3.4 test/perf_write.rb
ox-1.3.3 test/perf_write.rb
ox-1.3.2 test/perf_write.rb
ox-1.3.1 test/perf_write.rb
ox-1.3.0 test/perf_write.rb
ox-1.2.15 test/perf_write.rb
ox-1.2.14 test/perf_write.rb