"Why does Process.fork make things slower in Ruby on OS X?"
Step one is to minimize the number of variables.
Your example of running Time.parse(Time.utc(2016).iso8601) fifty thousand times seems strange. I reformulated a test test using another βslowβ Ruby task:
require 'benchmark' def do_stuff a = [nil] * 200 10.times do a.each {|x| a.each {|y| a.each {|z| ; }}}; () end end puts "main: #{Benchmark.measure { do_stuff }}" Process.fork do puts "fork: #{Benchmark.measure { do_stuff }}" end
Here I replaced your Time commands with a no-op nested loop with a large array.
Results:
main: 4.020000 0.010000 4.030000 ( 4.050664) fork: 3.940000 0.000000 3.940000 ( 3.962207) main: 3.840000 0.010000 3.850000 ( 3.856188) fork: 3.850000 0.000000 3.850000 ( 3.865250) main: 3.930000 0.000000 3.930000 ( 3.937741) fork: 3.970000 0.000000 3.970000 ( 3.986397) main: 4.340000 0.010000 4.350000 ( 4.370009) fork: 4.300000 0.000000 4.300000 ( 4.308156)
The lack of a noticeable bifurcated process structure is slower or faster. I tested in Ruby 1.9, 2.0, and 2.3 on both OS X and Ubuntu, and it remains the same.
The answer to your question:
Process.fork , in general, doesn't make things slower in Ruby on OS X.
However, there is another interesting question: Why is `Time.utc` slower in a forked process in Ruby on OS X (and not Python)?
source share