Created
November 19, 2013 15:56
-
-
Save DiegoSalazar/7547566 to your computer and use it in GitHub Desktop.
Seeing threads sleep
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
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