Skip to content

Instantly share code, notes, and snippets.

@DiegoSalazar
Created November 19, 2013 15:56
Show Gist options
  • Select an option

  • Save DiegoSalazar/7547566 to your computer and use it in GitHub Desktop.

Select an option

Save DiegoSalazar/7547566 to your computer and use it in GitHub Desktop.
Seeing threads sleep
trials = 10
seconds = 1
threads = []
start_time = Time.now.to_f
trials.times do |i|
threads << Thread.new { sleep seconds }
end
threads.each &:join
puts "slept for #{Time.now.to_f - start_time} secs."
puts "without threads it would've been at least #{trials * seconds}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment