New Date value (v3)

Revision 3 of this benchmark created by Mathias Bynens on


Description

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.

Preparation HTML

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

Test runner

Ready to run.

Testing in
TestOps/sec
Using .valueOf()
new Date().valueOf();
ready
Using .getTime()
new Date().getTime();
ready
+new Date()
+new Date();
ready
+new Date
+new Date;
ready
Date.now()
Date.now();
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.