Last active
August 29, 2015 14:26
-
-
Save yorickpeterse/5688de0ffcaf9ec2a1ad to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$:.unshift(File.expand_path('../lib', __FILE__)) | |
require 'oga' | |
require 'benchmark/ips' | |
require 'nokogiri' | |
query = 'foo/bar/baz > 20' | |
ast = Oga::XPath::Parser.new(query).parse | |
compiler = Oga::XPath::Compiler.new | |
block = compiler.compile(ast) | |
document = Oga.parse_xml <<-EOF | |
<foo a="b"> | |
<bar> | |
<baz>20</baz> | |
</bar> | |
</foo> | |
EOF | |
noko_doc = Nokogiri::XML(document.to_xml) | |
Benchmark.ips do |bench| | |
bench.report 'evaluator' do | |
document.xpath(query) | |
end | |
bench.report 'compiler' do | |
block.call(document) | |
end | |
bench.report 'nokogiri' do | |
noko_doc.xpath(query) | |
end | |
bench.compare! | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Calculating ------------------------------------- | |
evaluator 2.561k i/100ms | |
compiler 17.500k i/100ms | |
nokogiri 3.527k i/100ms | |
------------------------------------------------- | |
evaluator 27.254k (± 0.2%) i/s - 138.294k | |
compiler 215.488k (± 6.9%) i/s - 1.085M | |
nokogiri 40.283k (± 3.8%) i/s - 204.566k | |
Comparison: | |
compiler: 215487.9 i/s | |
nokogiri: 40282.7 i/s - 5.35x slower | |
evaluator: 27254.3 i/s - 7.91x slower |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment