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
thread_started_at = Time.now | |
thread_finished_at = nil | |
for i in 1..4 do | |
Thread.start(i) do |t| | |
puts "started thread #{t}" | |
sleep 1 | |
puts "finished thread #{t}" | |
thread_finished_at = Time.now if t == 4 | |
end | |
end | |
loop_started_at = Time.now | |
for i in 1..4 do | |
puts "started loop #{i}" | |
sleep 1 | |
puts "finished loop #{i}" | |
end | |
loop_finished_at = Time.now | |
puts "Thread finished in #{thread_finished_at - thread_started_at}" | |
puts "Loop finished in #{loop_finished_at - loop_started_at}" |
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
[23] pry(2.1.5-p273)> edit | |
started thread 4 | |
started thread 2 | |
started thread 3 | |
started loop 1 | |
started thread 1 | |
finished thread 4finished thread 2 | |
finished loop 1 | |
started loop 2 | |
finished thread 3 | |
finished thread 1 | |
finished loop 2 | |
started loop 3 | |
finished loop 3 | |
started loop 4 | |
finished loop 4 | |
Thread finished in 1.001928 | |
Loop finished in 4.003844 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
SES のメール送信処理とかで時間がかかるやつは CPU に待ち時間が発生しているのでスレッドにする方がよさそう。