Skip to content

Instantly share code, notes, and snippets.

@mattyoho
Created December 19, 2011 21:33
Show Gist options
  • Save mattyoho/1498986 to your computer and use it in GitHub Desktop.
Save mattyoho/1498986 to your computer and use it in GitHub Desktop.
Interesting Array.new construction example
# Example pulled from https://github.com/raggi/typhoeus/blob/c683b7d2f0ba3fd01f962b9eb3e0a0307bd0f0f6/benchmarks/vs_nethttp.rb
q = Queue.new
threads = Array.new(calls) { Thread.new { q.pop.call } }
benchmark do |t|
t.report("net/http") do
responses = []
calls.times do |i|
q << lambda { open("http://127.0.0.1:3000/#{i}").read }
responses << threads[i]
end
responses.each {|r| raise unless r.value == "whatever"}
end
t.report("typhoeus") do
responses = []
calls.times do |i|
responses << @klass.get("http://127.0.0.1:3000/#{i}")
end
responses.each {|r| raise unless r.body == "whatever"}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment