Archive for the ‘code’ tag
Ruby Mail on CRuby, JRuby and IronRuby
Today I tried Mikel Lindsaar’s Mail gem on CRuby, JRuby and IronRuby.
Installation of each Ruby version and Mail gem was really easy so I will not describe it here. What interested me was how fast was Mail on each Ruby implementation.
I have created a simple mail and saved it as 1.eml.
Date: Thu, 24 Dec 2009 14:37:34 Central European Standard Time From: from@test.com To: to@test.com Message-ID: <4b336e9e762a0_a1014263a4689d3@2003-ie7.mail> Subject: This is a test email Mime-Version: 1.0 Content-Type: text/plain; charset="US-ASCII"; Content-Transfer-Encoding: 7bit Some text for mail body
This script will read the file, display subject and time elapsed (in seconds).
time = Time.now
require "rubygems"
require "mail"
mail = Mail.read("1.eml")
puts mail.subject.to_s
puts Time.now - time
I have executed the script three times for each Ruby implementation. It looks to me that CRuby and JRuby are similar in speed, and IronRuby is way slower.
| Test Run | CRuby | JRuby | IronRuby |
|---|---|---|---|
| 1 | 2.594 | 3.0 | 9.8125 |
| 2 | 2.109 | 2.016 | 7.796875 |
| 3 | 2.11 | 2.0 | 7.6875 |
Extend Watir
I had to click a h4 headline.
<h4 id="addproject">Create a new project</h4>
This did not work.
browser.h4(:id, "addproject").click
I posted a question to wtr-general mailing list and Bret Pettichord suggested to extend Watir with this, so it would support h4 headlines.
module Watir
class H4 < NonControlElement
TAG = 'H4'
end
module Container
def h4(how, what)
return H4.new(self, how, what)
end
end
end
Now this works.
browser.h4(:id, "addproject").click
Find Element by XPath
I had to click a h4 headline.
<h4 id="addproject">Create a new project</h4>
This did not work.
browser.h4(:id, "addproject").click
I posted a question to wtr-general mailing list and Angrez Singh was kind enough to help.
This will click h4 headline.
browser.element_by_xpath("//h4[@id='addproject']").click

