New Date value (v9)

Revision 9 of this benchmark created by Jinpu Hu 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.

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

Preparation HTML

<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

Ready to run.

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

Revisions

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