Skip to content

Instantly share code, notes, and snippets.

@JonathonMA
Created April 10, 2015 11:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JonathonMA/b4552a2ccb80949b47d3 to your computer and use it in GitHub Desktop.
Save JonathonMA/b4552a2ccb80949b47d3 to your computer and use it in GitHub Desktop.
require 'fruity'
def bench(desc)
puts desc
Fruity.compare do
time_now { Time.now; nil }
time_now_utc { Time.now.utc; nil }
end
end
bench "prefork"
Process.fork do
bench "child"
end
Process.wait
bench "parent"
@JonathonMA
Copy link
Author

OS X 10.10.2

prefork
Running each test 8192 times. Test will take about 1 second.
time_now is faster than time_now_utc by 4x ± 1.0
child
Running each test 4096 times. Test will take about 8 seconds.
time_now is faster than time_now_utc by 130x ± 10.0
parent
Running each test 8192 times. Test will take about 1 second.
time_now is faster than time_now_utc by 4x ± 1.0

@JonathonMA
Copy link
Author

Docker image ruby:2.1.5-wheezy

prefork
Running each test 2048 times. Test will take about 1 second.
time_now is faster than time_now_utc by 2x ± 1.0
child
Running each test 2048 times. Test will take about 1 second.
time_now is faster than time_now_utc by 3x ± 0.1
parent
Running each test 2048 times. Test will take about 1 second.
time_now is faster than time_now_utc by 3x ± 0.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment