-
-
Save nandokakimoto/e03e6b6535e33b7dd82749fad4e3f994 to your computer and use it in GitHub Desktop.
This file contains 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
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