Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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