Skip to content

Instantly share code, notes, and snippets.

@nandokakimoto
Last active July 25, 2017 15:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nandokakimoto/e03e6b6535e33b7dd82749fad4e3f994 to your computer and use it in GitHub Desktop.
Save nandokakimoto/e03e6b6535e33b7dd82749fad4e3f994 to your computer and use it in GitHub Desktop.
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