【发布时间】:2016-12-15 03:00:07
【问题描述】:
有人可以向我解释为什么Process.fork 在 Ruby 中让事情变得如此缓慢吗?我在 OS X El Capitan 上使用 Ruby 2.3.1。
require 'time'
require 'benchmark'
def do_stuff
50000.times { Time.parse(Time.utc(2016).iso8601) }
end
puts Benchmark.measure { do_stuff } # => 1.660000 0.010000 1.670000 ( 1.675466)
Process.fork do
puts Benchmark.measure { do_stuff } # => 3.170000 6.250000 9.420000 ( 9.508235)
end
编辑:刚刚注意到在 Linux(经过测试的 Debian 或 Ubuntu)上运行该代码不会对性能产生负面影响。
【问题讨论】:
标签: ruby macos performance unix fork