Sha256: 52ac69ce585cd6196e7a5429807cfe7bd80e02daffdc037038a3b4d531b7e6db

Contents?: true

Size: 900 Bytes

Versions: 4

Compression:

Stored size: 900 Bytes

Contents

$:.unshift(Dir.pwd + "/lib")
require 'rubygems'
require 'hpricot'
require 'xml'
require 'rexml/document'

ITERATIONS = 10
NESTED_ITERATIONS = 5

def bm(name, filename, &block)
  text = File.open(filename).read
  length = text.length / 1024.0 / 1024.0
  puts "#{filename}: #{name} (#{(length * 1024).round} kb)"
  for j in 0 .. NESTED_ITERATIONS
    s = Time.now.to_f
    for i in 0 .. ITERATIONS
      block.call(text)
    end
    timer = Time.now.to_f - s
    puts "\t#{length * ITERATIONS / timer} MB/s"
  end
end

def bm_suite(filenames)
  filenames.each do |filename|    
    bm("LIBXML THROUGHPUT:", filename) do |text|
      XML::Parser.string(text).parse
    end
    
    bm("HPRICOT THROUGHPUT:", filename) do |text|
      Hpricot.XML(text)
    end
    
    bm("REXML THROUGHPUT:", filename) do |text|
      REXML::Document.new(text)
    end
  end
end

bm_suite("script/benchmark/hamlet.xml")

Version data entries

4 entries across 4 versions & 3 rubygems

Version Path
libxml-jruby-modified-1.0.2-jruby script/benchmark/throughput.rb
libxml-jruby-modified-1.0.1-jruby script/benchmark/throughput.rb
libxml-fixed-jruby-1.0.0-jruby script/benchmark/throughput.rb
libxml-jruby-fixed-1.0.0-jruby script/benchmark/throughput.rb