Skip to content

Instantly share code, notes, and snippets.

@capotej
Created September 5, 2009 20:18
Show Gist options
  • Save capotej/181501 to your computer and use it in GitHub Desktop.
Save capotej/181501 to your computer and use it in GitHub Desktop.
require 'open-uri'
require 'benchmark'
def p
print '.'
end
#non threaded
u = Benchmark.measure do
open('http://www.yahoo.com').read;p
open('http://www.newsweek.com').read;p
open('http://www.amazon.com').read;p
end
puts "done #{u.real}"
#threaded
u = Benchmark.measure do
[
Thread.new { open('http://www.yahoo.com').read;p },
Thread.new { open('http://www.newsweek.com').read;p },
Thread.new { open('http://www.amazon.com').read;p }
].each { |x| x.join }
end
puts "done #{u.real}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment