
Untitled
By: a guest on
May 8th, 2012 | syntax:
None | size: 0.81 KB | hits: 16 | expires: Never
Ruby array inject
undefined method `+' for #<Thread:0x10b211590 dead> (NoMethodError)
from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/open-uri.rb:301:in `inject'
from client_test.rb:13:in `each'
from client_test.rb:13:in `inject'
from client_test.rb:13
require 'open-uri'
program_start_time = Time.now
threads = 10.times.map do
Thread.new do
time = Time.now
open('http://ca.yahoo.com/?p=us').read.length
Time.now-time
end
end
threads.map &:join
puts threads.inject() { |sum, e| sum + e.value}.to_f / threads.size
puts Time.now - program_start_time
puts threads.inject(0) { |sum, e| sum + e.value}.to_f / threads.size
threads.inject() { |sum, e| sum + e.value}.to_f / threads.size
threads.inject(0) { |sum, e| sum + e.value}.to_f / threads.size