Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 8th, 2012  |  syntax: None  |  size: 0.81 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Ruby array inject
  2. undefined method `+' for #<Thread:0x10b211590 dead> (NoMethodError)
  3.     from /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/1.8/open-uri.rb:301:in `inject'
  4.     from client_test.rb:13:in `each'
  5.     from client_test.rb:13:in `inject'
  6.     from client_test.rb:13
  7.        
  8. require 'open-uri'
  9. program_start_time = Time.now
  10. threads = 10.times.map do
  11.   Thread.new do
  12.     time = Time.now
  13.     open('http://ca.yahoo.com/?p=us').read.length
  14.     Time.now-time
  15.   end
  16. end
  17.  
  18. threads.map &:join
  19. puts threads.inject() { |sum, e| sum + e.value}.to_f / threads.size
  20. puts Time.now - program_start_time
  21.        
  22. puts threads.inject(0) { |sum, e| sum + e.value}.to_f / threads.size
  23.        
  24. threads.inject() { |sum, e| sum + e.value}.to_f / threads.size
  25.        
  26. threads.inject(0) { |sum, e| sum + e.value}.to_f / threads.size