Sha256: b214cda8ecab90f08ae97d2d40e25336a07ac33efd3a85cc7ec9f94e6946be27

Contents?: true

Size: 873 Bytes

Versions: 42

Compression:

Stored size: 873 Bytes

Contents

#!/usr/bin/env ruby

require 'rubygems'
require 'hpricot'
require 'xml'
require 'rexml/document'

ITERATIONS = 3
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::Document.file(filename)
    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("hamlet.xml")

Version data entries

42 entries across 42 versions & 1 rubygems

Version Path
libxml-ruby-2.2.0-x86-mingw32 script/benchmark/throughput
libxml-ruby-2.2.0 script/benchmark/throughput
libxml-ruby-2.1.2-x86-mingw32 script/benchmark/throughput
libxml-ruby-2.1.2 script/benchmark/throughput
libxml-ruby-2.1.1-x86-mingw32 script/benchmark/throughput
libxml-ruby-2.1.1 script/benchmark/throughput
libxml-ruby-2.1.0-x86-mingw32 script/benchmark/throughput
libxml-ruby-2.1.0 script/benchmark/throughput
libxml-ruby-2.0.9-x86-mingw32 script/benchmark/throughput
libxml-ruby-2.0.9 script/benchmark/throughput
libxml-ruby-2.0.6-x86-mingw32 script/benchmark/throughput
libxml-ruby-2.0.6 script/benchmark/throughput
libxml-ruby-2.0.5-x86-mingw32 script/benchmark/throughput
libxml-ruby-2.0.5 script/benchmark/throughput
libxml-ruby-2.0.4-x86-mingw32 script/benchmark/throughput
libxml-ruby-2.0.4 script/benchmark/throughput
libxml-ruby-2.0.3-x86-mingw32 script/benchmark/throughput
libxml-ruby-2.0.3 script/benchmark/throughput
libxml-ruby-2.0.2-x86-mingw32 script/benchmark/throughput
libxml-ruby-2.0.2 script/benchmark/throughput