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.9.0-x64-mingw32 script/benchmark/throughput
libxml-ruby-2.9.0 script/benchmark/throughput
libxml-ruby-2.8.0 script/benchmark/throughput
libxml-ruby-2.7.0-x86-mingw32 script/benchmark/throughput
libxml-ruby-2.7.0 script/benchmark/throughput
libxml-ruby-2.6.0-x86-mingw32 script/benchmark/throughput
libxml-ruby-2.6.0 script/benchmark/throughput
libxml-ruby-2.5.0-x86-mingw32 script/benchmark/throughput
libxml-ruby-2.5.0 script/benchmark/throughput
libxml-ruby-2.4.0-x86-mingw32 script/benchmark/throughput
libxml-ruby-2.4.0 script/benchmark/throughput
libxml-ruby-2.3.3-x86-mingw32 script/benchmark/throughput
libxml-ruby-2.3.3 script/benchmark/throughput
libxml-ruby-2.3.2 script/benchmark/throughput
libxml-ruby-2.3.0-x86-mingw32 script/benchmark/throughput
libxml-ruby-2.3.0 script/benchmark/throughput
libxml-ruby-2.2.2-x86-mingw32 script/benchmark/throughput
libxml-ruby-2.2.2 script/benchmark/throughput
libxml-ruby-2.2.1-x86-mingw32 script/benchmark/throughput
libxml-ruby-2.2.1 script/benchmark/throughput