Created
June 3, 2021 17:32
-
-
Save risentveber/5c448ba804db24336c184b037557b76a to your computer and use it in GitHub Desktop.
ruby test
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
require 'benchmark' | |
puts "You can also put forked code in a block pid: #{Process.pid}" | |
n = 100000 | |
t = Benchmark.realtime do | |
n.times do | |
Time.now.utc.strftime('%Y-%m-%dT%H:%M:%S.%6N') | |
end | |
end | |
puts "main total: #{t}, avg: #{t/n*1000}ms" | |
pid = fork do | |
n = 100000 | |
t = Benchmark.realtime do | |
n.times do | |
Time.now.utc.strftime('%Y-%m-%dT%H:%M:%S.%6N') | |
end | |
end | |
puts "fork total: #{t}, avg: #{t/n*1000}ms" | |
end | |
Process.wait(pid) if pid | |
puts "The parent process just skips over it: #{Process.pid}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment