Cleaned up the average timing benchmark.
This commit is contained in:
parent
203aea6b1a
commit
e54d77fc2f
|
@ -20,3 +20,27 @@ end
|
|||
def read_html
|
||||
return File.read(File.expand_path('../fixtures/gist.html', __FILE__))
|
||||
end
|
||||
|
||||
##
|
||||
# Benchmarks the average runtime of the given block.
|
||||
#
|
||||
# @param [Fixnum] amount The amount of times to call the block.
|
||||
# @param [Fixnum] precision
|
||||
#
|
||||
def measure_average(amount = 10, precision = 3)
|
||||
timings = []
|
||||
|
||||
amount.times do |iter|
|
||||
timing = Benchmark.measure { yield }.real
|
||||
|
||||
timings << timing.real
|
||||
|
||||
puts "Iteration: #{iter + 1}: #{timing.real.round(precision)}"
|
||||
end
|
||||
|
||||
average = timings.inject(:+) / timings.length
|
||||
|
||||
puts
|
||||
puts "Iterations: #{amount}"
|
||||
puts "Average: #{average.round(precision)} sec"
|
||||
end
|
||||
|
|
|
@ -1,21 +1,7 @@
|
|||
require_relative '../benchmark_helper'
|
||||
|
||||
xml = read_big_xml
|
||||
amount = 10
|
||||
timings = []
|
||||
xml = read_big_xml
|
||||
|
||||
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
|
||||
measure_average do
|
||||
Oga::XML::Lexer.new(xml).advance { }
|
||||
end
|
||||
|
||||
average = timings.inject(:+) / amount
|
||||
|
||||
puts
|
||||
puts "Iterations: #{amount}"
|
||||
puts "Average: #{average.round(3)} sec"
|
||||
|
|
Loading…
Reference in New Issue