Created
July 13, 2015 22:15
-
-
Save yorickpeterse/84f0c2f1f441a53c59d6 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]' | |
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>This is the baz node</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
end | |
Calculating ------------------------------------- | |
evaluator 2.613k i/100ms | |
compiler 18.386k i/100ms | |
nokogiri 3.561k i/100ms | |
------------------------------------------------- | |
evaluator 27.535k (± 6.2%) i/s - 138.489k | |
compiler 217.725k (±18.2%) i/s - 1.048M | |
nokogiri 39.600k (± 2.8%) i/s - 199.416k | |
Comparison: | |
compiler: 217725.3 i/s | |
nokogiri: 39600.0 i/s - 5.50x slower | |
evaluator: 27534.8 i/s - 7.91x slower |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment