0

I would like to determine the wall clock time a JavaScript function is called, with as much accuracy as possible. When my computer makes a call to JavaScript's Date().getTime() function, does it rely on the internal clock of the local/executing machine at all? If so, what system calls does getTime() make? And if not, how much error is there on average between the system clock and the time computed by getTime()?

This StackOverflow question partly addresses my issue but doesn't talk about any possibly latency. I also require much more precision in the computation: Is it safe to compare JavaScript's getTime() across different systems?

As a simplifying example, just assume I'm using a Windows machine running Windows 7.

Matt
  • 303
  • 1
  • 2
  • 16
  • 1
    getTime takes the time from the internal clock of the machine. – Alon Jun 06 '16 at 22:05
  • So your only question is about latency? That's impossible to answer definitively and is off–topic here. The language specification ([*ECMA-262*](http://www.ecma-international.org/ecma-262/6.0/)) does not define implementation in general or accuracy for [*getTime*](http://www.ecma-international.org/ecma-262/6.0/#sec-date.prototype.gettime). It's entirely implementation dependent and therefore likely to be different between implementations and platforms. – RobG Jun 06 '16 at 22:47
  • Actually `.getTime()` does nothing but access an internal field. The system calls (or whatever the implementation chooses to "*identify the current time*") happen in `new Date()`, `Date()` and `Date.now()`. – Bergi Jun 07 '16 at 01:48
  • More importantly, what browser (if any) are you executing this in on your Win7 machine? – Bergi Jun 07 '16 at 01:50
  • 1
    If you are looking for accuracy, you should have a look at [`performance.now()`](https://developer.mozilla.org/en-US/docs/Web/API/Performance/now) – Bergi Jun 07 '16 at 01:52
  • @Bergi, Firefox to be specific! Speaking of which, interesting suggestion. How does it differ from `Date()`, implementation-wise? – Matt Jun 07 '16 at 19:34
  • 1
    @Matt: Why not just read [the code](https://hg.mozilla.org/mozilla-central/file/tip/js/src/jsdate.cpp) yourself? FF is open source! :-D – Bergi Jun 08 '16 at 01:00

0 Answers0