Cleaned up benchmarking code.

This commit is contained in:
Yorick Peterse 2014-05-01 13:08:44 +02:00
parent ebf9099f0e
commit 203aea6b1a
12 changed files with 41 additions and 37 deletions

View File

@ -0,0 +1,22 @@
require 'benchmark'
require 'benchmark/ips'
require_relative '../lib/oga'
##
# 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__))
end
##
# Reads a normal sized HTML fixture.
#
# @return [String]
#
def read_html
return File.read(File.expand_path('../fixtures/gist.html', __FILE__))
end

View File

@ -1,7 +1,6 @@
require_relative '../../lib/oga' require_relative '../benchmark_helper'
require 'benchmark'
xml = File.read(File.expand_path('../../fixtures/big.xml', __FILE__)) xml = read_big_xml
amount = 10 amount = 10
timings = [] timings = []

View File

@ -1,7 +1,6 @@
require_relative '../../lib/oga' require_relative '../benchmark_helper'
require 'benchmark'
xml = File.read(File.expand_path('../../fixtures/big.xml', __FILE__)) xml = read_big_xml
Benchmark.bmbm(10) do |bench| Benchmark.bmbm(10) do |bench|
bench.report '10MB of XML' do bench.report '10MB of XML' do

View File

@ -1,5 +1,4 @@
require_relative '../../lib/oga' require_relative '../benchmark_helper'
require 'benchmark/ips'
string = 'Hello, how are you doing today?' string = 'Hello, how are you doing today?'
small = "<![CDATA[#{string}]]>" small = "<![CDATA[#{string}]]>"

View File

@ -1,5 +1,4 @@
require_relative '../../lib/oga' require_relative '../benchmark_helper'
require 'benchmark/ips'
simple = '<p>Hello world</p>' simple = '<p>Hello world</p>'
attributes = '<p class="foo">Hello world</p>' attributes = '<p class="foo">Hello world</p>'

View File

@ -1,7 +1,6 @@
require_relative '../../lib/oga' require_relative '../benchmark_helper'
require 'benchmark/ips'
html = File.read(File.expand_path('../../fixtures/gist.html', __FILE__)) html = read_html
Benchmark.ips do |bench| Benchmark.ips do |bench|
bench.report 'lex HTML' do bench.report 'lex HTML' do

View File

@ -1,7 +1,6 @@
require_relative '../../lib/oga' require_relative '../benchmark_helper'
require 'benchmark'
html = File.read(File.expand_path('../../fixtures/gist.html', __FILE__)) html = read_html
Benchmark.bmbm(20) do |bench| Benchmark.bmbm(20) do |bench|
bench.report 'lex HTML' do bench.report 'lex HTML' do

View File

@ -1,14 +1,6 @@
require_relative '../../lib/oga' require_relative '../benchmark_helper'
require 'benchmark'
fixture = File.expand_path('../../fixtures/big.xml', __FILE__) xml = read_big_xml
unless File.file?(fixture)
system('rake fixtures')
puts
end
xml = File.read(fixture)
lines = xml.lines.count lines = xml.lines.count
lexer = Oga::XML::Lexer.new(xml) lexer = Oga::XML::Lexer.new(xml)
timings = Benchmark.bm(20) do |bench| timings = Benchmark.bm(20) do |bench|

View File

@ -1,7 +1,6 @@
require_relative '../../lib/oga' require_relative '../benchmark_helper'
require 'benchmark'
xml = File.read(File.expand_path('../../fixtures/big.xml', __FILE__)) xml = read_big_xml
parser = Oga::XML::Parser.new(xml) parser = Oga::XML::Parser.new(xml)
Benchmark.bmbm(10) do |bench| Benchmark.bmbm(10) do |bench|

View File

@ -1,5 +1,4 @@
require_relative '../../lib/oga' require_relative '../benchmark_helper'
require 'benchmark/ips'
simple = '<p>Hello world</p>' simple = '<p>Hello world</p>'
attributes = '<p class="foo">Hello world</p>' attributes = '<p class="foo">Hello world</p>'

View File

@ -1,7 +1,6 @@
require_relative '../../lib/oga' require_relative '../benchmark_helper'
require 'benchmark/ips'
html = File.read(File.expand_path('../../fixtures/gist.html', __FILE__)) html = read_html
Benchmark.ips do |bench| Benchmark.ips do |bench|
bench.report 'parse HTML' do bench.report 'parse HTML' do

View File

@ -1,7 +1,6 @@
require_relative '../../lib/oga' require_relative '../benchmark_helper'
require 'benchmark'
xml = File.read(File.expand_path('../../fixtures/big.xml', __FILE__)) xml = read_big_xml
parser = Oga::XML::PullParser.new(xml) parser = Oga::XML::PullParser.new(xml)
Benchmark.bmbm(10) do |bench| Benchmark.bmbm(10) do |bench|