From 20f2f256f61f02e1ba822eed1abffe0e8c814908 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Thu, 1 May 2014 13:01:52 +0200 Subject: [PATCH] Benchmark for measuring average lexing times. --- benchmark/lexer/bench_big_xml_average.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 benchmark/lexer/bench_big_xml_average.rb diff --git a/benchmark/lexer/bench_big_xml_average.rb b/benchmark/lexer/bench_big_xml_average.rb new file mode 100644 index 0000000..4b1360b --- /dev/null +++ b/benchmark/lexer/bench_big_xml_average.rb @@ -0,0 +1,22 @@ +require_relative '../../lib/oga' +require 'benchmark' + +xml = File.read(File.expand_path('../../fixtures/big.xml', __FILE__)) +amount = 10 +timings = [] + +amount.times do |i| + timing = Benchmark.measure do + Oga::XML::Lexer.new(xml).advance { } + end + + puts "Iteration #{i + 1}: #{timing.real.round(3)}" + + timings << timing.real +end + +average = timings.inject(:+) / amount + +puts +puts "Iterations: #{amount}" +puts "Average: #{average.round(3)} sec"