Compare two integer timestamps using explicit units. The interval is calculated with integer arithmetic, including for microsecond and nanosecond logs.
When to use this check
Two services record the same operation with different timestamp units. Converting each to a JavaScript Date first would discard differences smaller than a millisecond. Scale both integers to nanoseconds before subtracting.
Reproduce the result
The first sample is in milliseconds and the second in nanoseconds. Run it to obtain 250000 ns, or 0.25 ms. Reverse their order and units to confirm the sign changes. A negative result means the second reading was earlier.
Interpret the result
Use timestamps from clocks with a shared epoch. Clock drift, buffering and unsynchronized hosts can make an interval misleading. Use monotonic measurements within the same process when measuring elapsed time.