From: Carlos Date: 2006-07-04T18:26:56+09:00 Subject: Re: open-uri speed 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} Doesn't this version open the connection only once and then reuses it for all the requests? > timing("open-uri") {n.times do |i| > open("http://www.pythonchallenge.com/pc/def/linkedlist.php") do |x| > x.read > end > end} This, I'm sure, doesn't reuse the connection. --