New Date value (v10)

Revision 10 of this benchmark created 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(1400117186000).valueOf();
ready
Using .getTime()
new Date(1400117186000).getTime();
ready
Using +new Date()
+new Date(1400117186000);
ready
Using +new Date
+new Date;
ready
Date.now()
Date.now();
ready
Date.now() dereferenced
datenow();
ready
Simple date
new Date(1400117186000);
ready

Revisions

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