On Jul 4, 2006, at 12:51 AM, Elliot Temple wrote:

> I just discovered this. Lots of people already know, I'm sure, but  
> maybe some don't.
>
>
> # net/http ran in: 128.734298 seconds.
> # open-uri ran in: 268.869359 seconds.
>
> require "net/http"
> require "open-uri"
>
>
> def timing(name)
>   start_time = Time.now
>   yield
>   end_time = Time.now
>   puts "#{name} ran in: #{end_time - start_time} seconds."
> end
>
> n = 1_000
>
> timing("net/http") {Net::HTTP.start("www.pythonchallenge.com") do | 
> http|
>   n.times do |i|
>     r = http.get("/pc/def/linkedlist.php")
>   end
> end}
>
> timing("open-uri") {n.times do |i|
>   open("http://www.pythonchallenge.com/pc/def/linkedlist.php") do |x|
>     x.read
>   end
> end}
>
>
>
>
> -- Elliot Temple
> http://www.curi.us/blog/
>
>
>
>

Well of course the second one takes longer. It parses the URI and  
then does the same thing as the first. There's at least one more  
method call involved with the second every time through the the loop.