Added ips benchmark for NodeSet#push

This commit is contained in:
Yorick Peterse 2015-08-19 01:20:27 +02:00
parent ed9ead4fc0
commit f5dae24c39
1 changed files with 17 additions and 0 deletions

View File

@ -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