Ruby usec
Two Time
objects are almost never equal:
2.2.2 :001 > t = Time.now; t2 = Time.now
=> 2015-08-11 19:22:39 -0500
2.2.2 :002 > t == t2
=> false
This is true despite the fact that they were created in the same second of time, which we can verify by casting them to integers.
2.2.2 :003 > t.to_i
=> 1439338959
2.2.2 :004 > t2.to_i
=> 1439338959
The difference between these two times is in microseconds, which aren't displayed by default. Cast them as floats to see the difference.
2.2.2 :005 > t.to_f
=> 1439338959.099774
2.2.2 :006 > t2.to_f
=> 1439338959.099776
Another path to this information is Ruby's usec
method, which returns just the microseconds.
2.2.2 :007 > t.usec
=> 99774
2.2.2 :008 > t2.usec
=> 99776
Tweet