public
Description: A feed fetching and parsing library that treats the internet like Godzilla treats Japan: it dominates and eats all.
Homepage:
Clone URL: git://github.com/pauldix/feedzirra.git
feedzirra / spec / benchmarks / updating_benchmarks.rb
100644 33 lines (28 sloc) 1.248 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
require 'rubygems'
require File.dirname(__FILE__) + '/../../lib/feedzirra.rb'
 
require 'benchmark'
include Benchmark
 
urls = File.readlines(File.dirname(__FILE__) + "/../sample_feeds/successful_feed_urls.txt")
puts "benchmarks on #{urls.size} feeds"
puts "************************************"
benchmark do |t|
  feeds = {}
  t.report("feedzirra fetch and parse") do
    feeds = Feedzirra::Feed.fetch_and_parse(urls,
      :on_success => lambda { |url, feed| $stdout.print '.'; $stdout.flush },
      :on_failure => lambda {|url, response_code, header, body| puts "#{response_code} ERROR on #{url}"})
  end
  
  # curb caches the dns lookups for 60 seconds. to make things fair we have to wait for the cache to expire
  puts "sleeping to wait for dns cache to clear"
  65.times {$stdout.print('.'); sleep(1)}
  puts "done"
  
  updated_feeds = []
  t.report("feedzirra update") do
    updated_feeds = Feedzirra::Feed.update(feeds.values.reject {|f| f.class == Fixnum},
      :on_success => lambda {|feed| $stdout.print '.'; $stdout.flush},
      :on_failure => lambda {|feed, response_code, header, body| puts "#{response_code} ERROR on #{feed.feed_url}"})
  end
  
  updated_feeds.each do |feed|
    puts feed.feed_url if feed.updated?
  end
end