Skip to content

Instantly share code, notes, and snippets.

@rich
Created July 21, 2009 02:09
Show Gist options
  • Select an option

  • Save rich/151055 to your computer and use it in GitHub Desktop.

Select an option

Save rich/151055 to your computer and use it in GitHub Desktop.
fp = '/Users/rich/stocks.test.xml'
n = 5
Benchmark.bm(7) do |x|
x.report("Hash.from_xml") do
n.times do
h = Hash.from_xml(open(fp).read)['stock_feed']
h['sector'].map{|s| s['stock'].map {|i| i['name']}.first}.flatten
end
end
x.report("NokoHash") do
n.times do
doc = Nokogiri::XML(open(fp))
h = NokoHash.new(doc)
h.sector.map{|s| s.stock.map {|i| i[:name]}.first}.flatten
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment