Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimization to Document#collect_namespaces suggested by #761.
Note that benchmarks indicate this is *much* faster: #! /usr/bin/env ruby require 'nokogiri' require 'benchmark' xhtml = File.read "test/files/tlm.html" n = 50 Benchmark.bm(20) do |b| docs = (1..n).collect { |_| Nokogiri::XML xhtml } b.report("using xpath (x#{n})") do docs.each do |doc| doc.collect_namespaces end end docs = (1..n).collect { |_| Nokogiri::XML xhtml } b.report("using traverse (x#{n})") do ENV['SLOW'] = "1" docs.each do |doc| doc.collect_namespaces end end end with the result: user system total real using xpath (x50) 0.590000 0.010000 0.600000 ( 0.605675) using traverse (x50) 2.410000 0.010000 2.420000 ( 2.431678)
- Loading branch information