From 361374c813d3b6cb636adea5d787e1784cd26620 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Thu, 7 May 2015 00:04:40 +0200 Subject: [PATCH] IPS benchmark for XPath::Evaluator#node_matches? --- .../xpath/evaluator/node_matches_bench.rb | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 benchmark/xpath/evaluator/node_matches_bench.rb diff --git a/benchmark/xpath/evaluator/node_matches_bench.rb b/benchmark/xpath/evaluator/node_matches_bench.rb new file mode 100644 index 0000000..d271019 --- /dev/null +++ b/benchmark/xpath/evaluator/node_matches_bench.rb @@ -0,0 +1,30 @@ +require_relative '../../benchmark_helper' + +xml_node = Oga::XML::Element.new(:name => 'foo') + +name_only = AST::Node.new(:test, [nil, 'foo']) +name_star = AST::Node.new(:test, [nil, '*']) +name_ns_star = AST::Node.new(:test, ['*', 'foo']) +name_ns = AST::Node.new(:test, ['bar', 'foo']) + +evaluator = Oga::XPath::Evaluator.new(xml_node) + +Benchmark.ips do |bench| + bench.report 'name only' do + evaluator.node_matches?(xml_node, name_only) + end + + bench.report 'name wildcard' do + evaluator.node_matches?(xml_node, name_star) + end + + bench.report 'name + namespace' do + evaluator.node_matches?(xml_node, name_ns) + end + + bench.report 'namespace wildcard' do + evaluator.node_matches?(xml_node, name_ns_star) + end + + bench.compare! +end