Skip to content

Instantly share code, notes, and snippets.

@wuputah
Created October 11, 2017 17:15
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 wuputah/d789450b7c93c5691e59ead3cfef9e38 to your computer and use it in GitHub Desktop.
Save wuputah/d789450b7c93c5691e59ead3cfef9e38 to your computer and use it in GitHub Desktop.
if Array.new(10) { Time.now.nsec % 1000 }.sum == 0
puts "nsec precision not available"
exit
end
a = 0
10_000_000.times do
t = Time.now
d = ( sprintf("%.9f", t.to_f).split('.')[1].to_i - t.nsec ).abs
# edge case around 0 nsec where .to_f results in .999999999
if d > 900_000_000
d = (d - 1_000_000_000).abs
end
raise "bug" if d > 1_000
a += d
end
puts a / 10_000_000.0 #=> 82.5188864, 82.4912323
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment