神刀安全网

RSS Collector in Ruby and Go

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
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 :

$ bundle install 

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

$ 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 andgofeed, only this.

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

$ 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:

$ 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!

转载本站任何文章请注明:转载至神刀安全网,谢谢神刀安全网 » RSS Collector in Ruby and Go

分享到:更多 ()

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址