Skip to content

Instantly share code, notes, and snippets.

@risentveber
Created June 3, 2021 17:32
Show Gist options
  • Save risentveber/5c448ba804db24336c184b037557b76a to your computer and use it in GitHub Desktop.
Save risentveber/5c448ba804db24336c184b037557b76a to your computer and use it in GitHub Desktop.
ruby test
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