New Date value

JavaScript performance comparison

Revision 9 of this test case created by Jinpu Hu

Info

Different ways of creating a valueOf() of a Date object.

Findings: in Opera 10.60, Chrome 5.0.375.125, Safari 5.0.1 (6533.17.8) and Firefox 3.6.8, Date.now() is the fastest. It’s more than 50% faster than +new Date(). Too bad IE8 and below don’t support it.

Certainty, dereferenced var datenow = Date.now is more faster than Date.now.

Preparation code

<script>
  // IE8 and below don’t support ES5 Date.now()
  !Date.now && (Date.now = function() {
    return new Date().valueOf();
  });
  var datenow = Date.now;
</script>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
Using .valueOf()
new Date().valueOf();
pending…
Using .getTime()
new Date().getTime();
pending…
Using +new Date()
+new Date();
pending…
Using +new Date
+new Date;
pending…
Date.now()
Date.now();
pending…
Date.now() dereferenced
datenow();
pending…

Compare results of other browsers

Revisions

You can edit these tests or add even more tests to this page by appending /edit to the URL. Here’s a list of current revisions for this page:

0 comments

Add a comment