Created
          March 26, 2009 08:23 
        
      - 
      
- 
        Save alno/85971 to your computer and use it in GitHub Desktop. 
    Benchmark for Ruby RSS parsers
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # Becnhmark for Ruby RSS parsers | |
| # Gems: syndication, rubyrss, simple-rss, feedtools | |
| require 'benchmark' | |
| require 'rubygems' | |
| require 'open-uri' | |
| require 'rss' | |
| require 'simple-rss' | |
| require 'feed_tools' | |
| require 'syndication/rss' | |
| require 'feed-normalizer' | |
| def process_items( channel ) | |
| for i in channel.items do | |
| i.link | |
| i.title | |
| i.description | |
| end | |
| end | |
| def process_entries( channel ) | |
| for i in channel.entries do | |
| i.url | |
| i.title | |
| i.description | |
| end | |
| end | |
| def test_feed( x, fn ) | |
| feed_uri = 'http://localhost/' + fn + '.xml' | |
| x.report(fn + ' std:') do | |
| rss = RSS::Parser.parse open( feed_uri ) | |
| process_items( rss.channel ) | |
| end | |
| x.report(fn + ' simple-rss:') do | |
| rss = SimpleRSS.parse open( feed_uri ) | |
| process_items( rss ) | |
| end | |
| x.report(fn + ' feed_tools:') do | |
| rss = FeedTools::Feed.open( feed_uri ) | |
| process_items( rss ) | |
| end | |
| x.report(fn + ' syndication:') do | |
| rss = Syndication::RSS::Parser.new.parse open( feed_uri ) | |
| process_items( rss ) | |
| end | |
| x.report(fn + ' feednormalizer:') do | |
| rss = FeedNormalizer::FeedNormalizer.parse open( feed_uri ) | |
| process_entries( rss ) | |
| end | |
| end | |
| Benchmark.bm( 30 ) do |x| | |
| test_feed( x, 'feed1' ) | |
| test_feed( x, 'feed2' ) | |
| end | |
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment