-
-
Save walf443/24167 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
100.times do | |
100.times do | |
th = Thread.fork do | |
File.open("/tmp/thread/#{Thread.current.object_id}", "w") do |io| | |
io.puts("a" * 10000) | |
end | |
end | |
th.join | |
end | |
end | |
100.times do | |
100.times do | |
Process.fork do | |
File.open("/tmp/fork/#{Process.pid}", "w") do |io| | |
io.puts("a" * 10000) | |
end | |
end | |
end | |
Process.waitall | |
end | |
# result | |
# $ time ruby fork.rb | |
# ruby fork.rb 17.97s user 32.23s system 110% cpu 45.501 total | |
# $ time ruby thread.rb | |
# ruby thread.rb 2.65s user 2.65s system 44% cpu 11.801 total | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment