Skip to content

Instantly share code, notes, and snippets.

@nandokakimoto

nandokakimoto/thread-io-bound.rb Secret

Last active Jul 25, 2017
Embed
What would you like to do?
require 'open-uri'
require 'benchmark'
URL = 'http://google.com'
TIMES = 10.times
def without_threads
TIMES.map { open(URL) }
end
def with_threads
TIMES.map do
Thread.new { open(URL) }
end.each(&:join)
end
puts "Without threads:"
puts Benchmark.measure { without_threads }
puts "With threads"
puts Benchmark.measure { with_threads }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.