Benchmark for measuring average lexing times.

This commit is contained in:
Yorick Peterse 2014-05-01 13:01:52 +02:00
parent f607cf50dc
commit 20f2f256f6
1 changed files with 22 additions and 0 deletions

View File

@ -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"