Advertisement
Azure

CR NP benchmarking script (full map vs selected map)

Mar 25th, 2012
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.05 KB | None | 0 0
  1. require 'benchmark'
  2. require 'nokogiri'
  3. require 'open-uri'
  4.  
  5. doc = Nokogiri::HTML(open('http://molestia.ponify.me:8062/index.html', 'User-Agent' => "Mozilla/5.0 Ruby/#{RUBY_VERSION}"))
  6.  
  7. Benchmark.bm do |x|
  8.   x.report("Full mapping:") {
  9.     #begin full table=>hash mapping
  10.  
  11.     stream_data = {}
  12.  
  13.     doc.xpath('//table[3]/tr').each do |row|
  14.       key = row.css('td')[0].content.strip.sub(':','').gsub(' ','_').downcase.to_sym
  15.       value = row.css('td')[1].content
  16.       stream_data[key] = value
  17.     end
  18.  
  19.     #puts stream_data.inspect
  20.   }
  21.  
  22.   x.report("Selected mapping:") {
  23.     #begin selected table=>hash mapping
  24.  
  25.     stream_data = {}
  26.     expected_prefixes = ["Stream Status", "Listener Peak", "Stream Title", "Current"]
  27.  
  28.     doc.xpath('//table[3]/tr').each do |row|
  29.       next unless row.css('td')[0].content.start_with?(*expected_prefixes)
  30.       key = row.css('td')[0].content.strip.sub(':','').gsub(' ','_').downcase.to_sym
  31.       value = row.css('td')[1].content
  32.       stream_data[key] = value
  33.     end
  34.  
  35.     #puts stream_data.inspect
  36.   }
  37. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement