Date.now vs Date.getTime

JavaScript performance comparison

Revision 3 of this test case created by Tarun

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var dateNowOrGetTime = function() {
            if (Date.now) {
              return Date.now();
            } else {
              return new Date().getTime();
            }
        };
};
</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
Date.now();
var foo = Date.now();
pending…
Date.getTime()
var foo = new Date().getTime();
pending…
Date.now() or Date.getTime()
var foo = dateNowOrGetTime();
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