Benchmarks/profilers for IO inputs in the lexer.

This commit is contained in:
Yorick Peterse 2014-05-26 00:31:03 +02:00
parent 629dcd3fe6
commit c81c6db74e
5 changed files with 41 additions and 2 deletions

View File

@ -1,15 +1,25 @@
require 'stringio'
require 'benchmark' require 'benchmark'
require 'benchmark/ips' require 'benchmark/ips'
require_relative '../lib/oga' require_relative '../lib/oga'
##
# Returns a File instance pointing to the sample XML file.
#
# @return [File]
#
def big_xml_file
return File.open(File.expand_path('../fixtures/big.xml', __FILE__), 'r')
end
## ##
# Reads a big XML file and returns it as a String. # Reads a big XML file and returns it as a String.
# #
# @return [String] # @return [String]
# #
def read_big_xml def read_big_xml
return File.read(File.expand_path('../fixtures/big.xml', __FILE__)) return big_xml_file.read
end end
## ##

View File

@ -0,0 +1,5 @@
require_relative '../benchmark_helper'
measure_average do
Oga::XML::Lexer.new(big_xml_file).advance { }
end

View File

@ -0,0 +1,7 @@
require_relative '../benchmark_helper'
Benchmark.bmbm(10) do |bench|
bench.report '10MB of XML using IO' do
Oga::XML::Lexer.new(big_xml_file).advance { |tok| }
end
end

View File

@ -0,0 +1,5 @@
require_relative '../profile_helper'
profile_memory('lexer/big_xml') do
Oga::XML::Lexer.new(big_xml_file).advance { }
end

View File

@ -1,4 +1,5 @@
require 'timeout' require 'timeout'
require 'stringio'
require_relative '../lib/oga' require_relative '../lib/oga'
@ -20,13 +21,24 @@ def memory_usage
return kb * 1024 return kb * 1024
end end
##
# Returns a File instance pointing to the sample XML file.
#
# @return [File]
#
def big_xml_file
path = File.expand_path('../../benchmark/fixtures/big.xml', __FILE__)
return File.open(path, 'r')
end
## ##
# Reads a big XML file and returns it as a String. # Reads a big XML file and returns it as a String.
# #
# @return [String] # @return [String]
# #
def read_big_xml def read_big_xml
return File.read(File.expand_path('../../benchmark/fixtures/big.xml', __FILE__)) return big_xml_file.read
end end
## ##