Rodrigo Martins

I'm a Catholic Christian, software developer, Passionate about life, codes, questions, theories and theorems. :)

RSS Collector in Ruby and Go

| Comments

Hi,

My idea is to do a project in Go and Ruby, to make a simple parse the same url to an rss feed, and check how long it takes each run of languages.

Come on!

Ruby

Let’s first talk about the project in Ruby.

We will have a class called Parse::Rss, with some methods, as: get_title(), get_description(), get_link(), get_categories(), get_total_items().

We used the rrsimple-rss and open-uri gem. Below is ready class. I do not do anything different, but to do the get the fields that the gem returns.

The main file, start the url variable with a value already set and start the Parse :: Rss class. initializing the class will already run parse the url and return the object that the gem returns.

initializing url and Parse with url
1
2
url = "http://golangweekly.com/rss/1g2bo910"
parserss = Parse::Rss.new(url)

Now is print the returns.

We run bundle install to install the gems of Gemfile:

1
$ bundle install

When running main.rb file return of the Parse::Rss class and execution of time:

1
2
3
4
5
6
7
8
$ ruby main.rb
The Title is: Go Newsletter
The Description is: A weekly newsletter about the Go programming language
The Link is: http://golangweekly.com/
The Categories is No have Categories
The total of Items is: 4

  0.360000   0.020000   0.380000 (  4.406442)

Project on github: parserssrb

Go

Now let’s talk about the project in Go.

We use go from the standard libraries, as: fmt, time and gofeed, only this.

As we have an external package, you will need to install using:

1
$ go get github.com/mmcdole/gofeed

Ok!

Now create the file parse/rss.go, in package parse:

We create main.go in root path, this file we used time to calculate time run the project.

When running main.go file:

1
2
3
4
5
6
7
8
9
$ go run main.go
Starting get
The Title is: Go Newsletter
The Description is: A weekly newsletter about the Go programming language
The Link is: http://golangweekly.com/
The Categories is No have Categories
The total of Items is: 4

Benchmark: 2.20670856s

Project on github: grfeed

In a quick comparison with the “same” functionality, Go was faster than Ruby.

Thanks! Until next time!

Comments