From f5dae24c39f9423a43d6309cd11c6d2a3a9454a9 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Wed, 19 Aug 2015 01:20:27 +0200 Subject: [PATCH] Added ips benchmark for NodeSet#push --- benchmark/xml/node_set/push_bench.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 benchmark/xml/node_set/push_bench.rb diff --git a/benchmark/xml/node_set/push_bench.rb b/benchmark/xml/node_set/push_bench.rb new file mode 100644 index 0000000..5649efb --- /dev/null +++ b/benchmark/xml/node_set/push_bench.rb @@ -0,0 +1,17 @@ +require_relative '../../benchmark_helper' + +# Assigning to an Array first saves the need (and overhead) of calling #push for +# every iteration. +initial = 20_000.times.map do |number| + Oga::XML::Element.new(:name => number.to_s) +end + +initial = Oga::XML::NodeSet.new(initial) + +Benchmark.ips do |bench| + bench.report 'XML::NodeSet#push' do + new_set = Oga::XML::NodeSet.new + + initial.each { |node| new_set << node } + end +end