Benchmark for lexer lines/second.
This benchmark uses a fixture file that is automatically downloaded.
This commit is contained in:
parent
54e6650338
commit
6f1ce17b31
|
@ -5,3 +5,5 @@ Gemfile.lock
|
||||||
|
|
||||||
lib/oga/xml/lexer.rb
|
lib/oga/xml/lexer.rb
|
||||||
lib/oga/xml/parser.rb
|
lib/oga/xml/parser.rb
|
||||||
|
|
||||||
|
benchmark/fixtures/big.xml
|
||||||
|
|
8
Rakefile
8
Rakefile
|
@ -8,7 +8,13 @@ GEMSPEC = Gem::Specification.load('oga.gemspec')
|
||||||
LEXER_OUTPUT = 'lib/oga/xml/lexer.rb'
|
LEXER_OUTPUT = 'lib/oga/xml/lexer.rb'
|
||||||
PARSER_OUTPUT = 'lib/oga/xml/parser.rb'
|
PARSER_OUTPUT = 'lib/oga/xml/parser.rb'
|
||||||
|
|
||||||
GENERATED_FILES = ['coverage', 'yardoc', LEXER_OUTPUT, PARSER_OUTPUT]
|
GENERATED_FILES = [
|
||||||
|
'coverage',
|
||||||
|
'yardoc',
|
||||||
|
LEXER_OUTPUT,
|
||||||
|
PARSER_OUTPUT,
|
||||||
|
'benchmark/fixtures/big.xml'
|
||||||
|
]
|
||||||
|
|
||||||
GENERATED_FILES.each do |file|
|
GENERATED_FILES.each do |file|
|
||||||
CLEAN << file if File.exist?(file)
|
CLEAN << file if File.exist?(file)
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
require_relative '../../lib/oga'
|
||||||
|
require 'benchmark'
|
||||||
|
|
||||||
|
fixture = File.expand_path('../../fixtures/big.xml', __FILE__)
|
||||||
|
|
||||||
|
unless File.file?(fixture)
|
||||||
|
system('rake fixtures')
|
||||||
|
puts
|
||||||
|
end
|
||||||
|
|
||||||
|
xml = File.read(fixture)
|
||||||
|
lines = xml.lines.count
|
||||||
|
lexer = Oga::XML::Lexer.new(xml)
|
||||||
|
timings = Benchmark.bm(20) do |bench|
|
||||||
|
bench.report("#{lines} lines") do
|
||||||
|
lexer.advance { |_| }
|
||||||
|
lexer.reset
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
time = timings[0].real
|
||||||
|
rate = lines / time
|
||||||
|
|
||||||
|
puts
|
||||||
|
puts "Lines/second: #{rate.round(3)}"
|
|
@ -0,0 +1,9 @@
|
||||||
|
desc 'Generates large XML fixtures'
|
||||||
|
task :fixtures do
|
||||||
|
dest = File.expand_path('../../benchmark/fixtures/big.xml.gz', __FILE__)
|
||||||
|
|
||||||
|
unless File.file?(dest)
|
||||||
|
sh "wget http://downloads.yorickpeterse.com/files/big_xml_file.xml.gz -O #{dest}"
|
||||||
|
sh "gunzip #{dest}"
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue