+new Date vs Date.now() vs performance.now()

JavaScript performance comparison

Revision 25 of this test case created

Info

https://twitter.com/jaffathecake/status/306706682552143872

jaffathecake: Avoid "+new Date" to generate timestamps during animation. Use "Date.now()" or "performance.now()" instead http://t.co/Hle0qzxWeZ

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var perf = performance;
    var pnow = perf.now;
    var dnow = Date.now;
    var round = Math.round;
    var getp = function () {return perf.now()};
    var getpr = function () {return Math.round(perf.now())};
    var getprc = function () {return round(perf.now())};
    var getpc = function () {return pnow()};
    var getdc = function () {return dnow()};
    var getd = function () {return 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
Date.now
getp()
pending…
+new Date()
getpc()
pending…
performance.now()
getd()
pending…
new Date().getTime()
getpr()
pending…
new Date().valueOf()
getprc()
pending…
Cached performance object
getdc()
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