from JSC to all others: preciseTime global function ?

Andrea Giammarchi andrea.giammarchi at gmail.com
Thu Aug 16 05:02:10 PDT 2012


looks like the result would be the same obtained via preciseTime() *
1000000 ... I just wonder why this is a W3C draft rather than a ECMAScript
one.

meanwhile ... for JSC, Rhino, node.js, and browsers ...

// JSC has it right, kudos!
(typeof preciseTime == "undefined" && function(exports){
  var preciseTime;
  try {
    // node.js + does it work ?
    (preciseTime = require("microtime").nowDouble)();
  } catch(o_O) {
    try {
      // Rhino + does it work ?
      var nanoTime = java.lang.System.nanoTime;
      (preciseTime = function preciseTime() {
        return nanoTime() / 1000000000;
      })();
    } catch(o_O) {
      // browsers ... it works
      preciseTime = function preciseTime() {
        return new Date / 1000;
      };
    }
  }
  exports.preciseTime = preciseTime;
}(this));

//* test
var t = [+new Date / 1000, this.preciseTime()];
try {
  console.log(t);
} catch(o_O) {
  try {
    alert(t);
  } catch(o_O) {
    print(t);
  }
}
//*/

br,
    Andrea Giammarchi

On Thu, Aug 16, 2012 at 12:45 PM, David Bruant <bruant.d at gmail.com> wrote:

>  What about high resolution time?
> http://dvcs.w3.org/hg/webperf/raw-file/tip/specs/HighResolutionTime/Overview.html
>
> David
>
> Le 16/08/2012 13:42, Andrea Giammarchi a écrit :
>
> Quick one, since I have discovered this only recently via
> Object.keys(this) in JSC ( JavaScriptCore )
>
>  double <= preciseTime()
>
>  returns a double number with seconds and microseconds, e.g.
>
>  12334556.123456
>
>  is basically the same of doing (new Date / 1000) except the precision is
> up to 1000000.
>
>  in Java/Rhino, System.nanoTime() / 1000000000 would produce similar
> result, but I found preciseTime() accurate enough but not as slow as
> nanoTime historically is ( greedy in clocks )
>
>  Is ES6 considering this function? I find hilarious that all JS
> benchmarks out there are basically asking browsers to enable a Java Applet
> in order to have better precision ( without considering that both binding
> and callback are more expensive than any +new Date call )
>
>  Thanks for any sort of answer.
>
>  Best Regards,
>     Andrea Giammarchi
>
>
> _______________________________________________
> es-discuss mailing listes-discuss at mozilla.orghttps://mail.mozilla.org/listinfo/es-discuss
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120816/55d7831a/attachment.html>


More information about the es-discuss mailing list