Skip to content

Instantly share code, notes, and snippets.

Created November 12, 2008 14:05
Show Gist options
  • Save anonymous/24163 to your computer and use it in GitHub Desktop.
Save anonymous/24163 to your computer and use it in GitHub Desktop.
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