From c81c6db74e60000f780e71ab962fc3d8be57928b Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Mon, 26 May 2014 00:31:03 +0200 Subject: [PATCH] Benchmarks/profilers for IO inputs in the lexer. --- benchmark/benchmark_helper.rb | 12 +++++++++++- benchmark/lexer/big_xml_io_average.rb | 5 +++++ benchmark/lexer/big_xml_io_time.rb | 7 +++++++ profile/lexer/big_xml_io.rb | 5 +++++ profile/profile_helper.rb | 14 +++++++++++++- 5 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 benchmark/lexer/big_xml_io_average.rb create mode 100644 benchmark/lexer/big_xml_io_time.rb create mode 100644 profile/lexer/big_xml_io.rb diff --git a/benchmark/benchmark_helper.rb b/benchmark/benchmark_helper.rb index 0cd2145..2bf70f6 100644 --- a/benchmark/benchmark_helper.rb +++ b/benchmark/benchmark_helper.rb @@ -1,15 +1,25 @@ +require 'stringio' require 'benchmark' require 'benchmark/ips' 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. # # @return [String] # def read_big_xml - return File.read(File.expand_path('../fixtures/big.xml', __FILE__)) + return big_xml_file.read end ## diff --git a/benchmark/lexer/big_xml_io_average.rb b/benchmark/lexer/big_xml_io_average.rb new file mode 100644 index 0000000..23757e3 --- /dev/null +++ b/benchmark/lexer/big_xml_io_average.rb @@ -0,0 +1,5 @@ +require_relative '../benchmark_helper' + +measure_average do + Oga::XML::Lexer.new(big_xml_file).advance { } +end diff --git a/benchmark/lexer/big_xml_io_time.rb b/benchmark/lexer/big_xml_io_time.rb new file mode 100644 index 0000000..ad5ed96 --- /dev/null +++ b/benchmark/lexer/big_xml_io_time.rb @@ -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 diff --git a/profile/lexer/big_xml_io.rb b/profile/lexer/big_xml_io.rb new file mode 100644 index 0000000..2d75750 --- /dev/null +++ b/profile/lexer/big_xml_io.rb @@ -0,0 +1,5 @@ +require_relative '../profile_helper' + +profile_memory('lexer/big_xml') do + Oga::XML::Lexer.new(big_xml_file).advance { } +end diff --git a/profile/profile_helper.rb b/profile/profile_helper.rb index a206683..ea98355 100644 --- a/profile/profile_helper.rb +++ b/profile/profile_helper.rb @@ -1,4 +1,5 @@ require 'timeout' +require 'stringio' require_relative '../lib/oga' @@ -20,13 +21,24 @@ def memory_usage return kb * 1024 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. # # @return [String] # def read_big_xml - return File.read(File.expand_path('../../benchmark/fixtures/big.xml', __FILE__)) + return big_xml_file.read end ##