Created
December 19, 2011 21:33
-
-
Save mattyoho/1498986 to your computer and use it in GitHub Desktop.
Interesting Array.new construction example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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