Created
August 7, 2013 23:23
-
-
Save othiym23/6179922 to your computer and use it in GitHub Desktop.
When I run this using 0.10.15 on "Darwin bauchelain.local 12.4.0 Darwin Kernel Version 12.4.0: Wed May 1 17:57:12 PDT 2013; root:xnu-2050.24.15~1/RELEASE_X86_64 x86_64", instead of getting a roughly stable value, I get one that steadily (but not consistently) increases. Are my units wrong? Is V8's timer that out to lunch?
This file contains 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
function hrToMillis(hr) { | |
return (hr[0] * 1e3) + (hr[1] / 1e6); | |
} | |
function wtf() { | |
return Date.now() - hrToMillis(process.hrtime()); | |
} | |
var basis = wtf(); | |
// output will grow, but non-monotonically | |
setInterval(function () { console.log(wtf() - basis ); }, 500); |
This file contains 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
14.513427734375 | |
15.303466796875 | |
15.666259765625 | |
15.363037109375 | |
15.42578125 | |
16.18408203125 | |
16.325439453125 | |
16.84228515625 | |
16.871337890625 | |
16.511474609375 | |
17.25048828125 | |
16.783203125 | |
16.892333984375 | |
17.9775390625 | |
17.783935546875 | |
17.49072265625 | |
18.184814453125 | |
18.623779296875 | |
18.278564453125 | |
18.9873046875 | |
18.65185546875 | |
19.53076171875 | |
19.301025390625 | |
19.9423828125 | |
19.769775390625 | |
19.615234375 | |
20.3681640625 | |
20.093994140625 | |
19.85791015625 | |
20.780517578125 | |
21.1123046875 | |
20.765869140625 | |
20.822265625 | |
21.179443359375 | |
21.926513671875 | |
21.62939453125 | |
21.555908203125 | |
22.371826171875 | |
22.1591796875 | |
22.8134765625 | |
22.279541015625 | |
23.013427734375 | |
22.6318359375 | |
23.264404296875 | |
22.946533203125 | |
23.712646484375 | |
23.68310546875 | |
23.964599609375 | |
23.740478515625 | |
24.3515625 | |
24.486083984375 | |
25.10302734375 | |
24.79150390625 | |
24.99267578125 | |
25.06689453125 | |
25.333740234375 | |
25.377197265625 | |
26.304443359375 | |
26.385986328125 | |
26.128662109375 | |
26.801513671875 | |
26.632080078125 | |
27.421630859375 | |
27.210205078125 | |
27.032958984375 | |
27.806884765625 | |
27.51318359375 | |
28.21337890625 | |
27.91650390625 | |
28.62841796875 | |
28.350341796875 | |
29.078857421875 | |
28.86279296875 | |
29.354736328125 | |
29.1328125 | |
29.945068359375 | |
29.7119140625 | |
30.42529296875 | |
29.915771484375 | |
30.744140625 | |
30.44921875 | |
31.18994140625 | |
30.95947265625 | |
31.706298828125 | |
31.493408203125 | |
31.24658203125 | |
31.98876953125 | |
31.755126953125 | |
31.95947265625 | |
32.6865234375 | |
32.594970703125 | |
32.40576171875 | |
32.5048828125 | |
33.581298828125 | |
32.96875 | |
33.92529296875 | |
33.683837890625 | |
34.42919921875 | |
34.14501953125 | |
34.854736328125 | |
34.551025390625 | |
35.192138671875 | |
34.811767578125 | |
34.9716796875 | |
34.7265625 | |
35.305908203125 | |
35.927734375 | |
35.712158203125 | |
36.287841796875 | |
36.1240234375 | |
35.9296875 | |
36.701904296875 | |
36.29052734375 | |
37.363037109375 | |
37.247802734375 | |
37.133544921875 | |
37.89501953125 | |
37.641845703125 | |
38.2734375 | |
38.139892578125 | |
38.79638671875 | |
39.13134765625 | |
38.941162109375 | |
38.675048828125 | |
39.067138671875 | |
39.506591796875 | |
39.82666015625 | |
39.39208984375 | |
40.2412109375 | |
39.9482421875 | |
40.684326171875 | |
40.502685546875 | |
41.196044921875 | |
41.363525390625 | |
41.58935546875 | |
41.351806640625 | |
41.111083984375 | |
41.8701171875 | |
41.5673828125 | |
42.22607421875 | |
42.630859375 | |
42.36181640625 | |
43.1201171875 | |
42.62255859375 | |
43.2470703125 | |
42.879638671875 | |
43.6796875 | |
43.406982421875 | |
43.635009765625 | |
44.596923828125 | |
44.02197265625 | |
44.637451171875 | |
44.392822265625 | |
44.9931640625 | |
44.8056640625 | |
45.507080078125 | |
45.210205078125 | |
46.004150390625 | |
45.78271484375 | |
45.87353515625 | |
46.787841796875 | |
46.185546875 | |
47.02294921875 | |
46.789794921875 | |
47.5830078125 | |
47.342529296875 | |
47.60205078125 | |
47.4267578125 | |
48.267333984375 | |
47.9951171875 | |
48.66748046875 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Mine drifts some too...
$ node drift.js
$ node -v; uname -a
Since process.hrtime() "is not related to the time of day and therefore not subject to clock drift", I think you've built yourself a handy little tool to measure a machine's hardware clock quality, and you are seeing your CLOCK_REALTIME slewing relative to your CLOCK_MONOTONIC, +/- clock jitter (btw, darwin is using mach_absolute_time under the hood, compared to other un*xes using clock_gettime(CLOCK_MONOTONIC). Win uses QueryPerformanceCounter).
Your script run results do seem to drift pretty quickly. Does the magnitude of clock frequency error measurement in your ntp driftfile correlate with your script results?