Created
October 11, 2017 17:15
-
-
Save wuputah/d789450b7c93c5691e59ead3cfef9e38 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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