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

Revision 17 of this benchmark created on


Description

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 HTML

<script>
window.saveIt = function(x){
    var saveIt2 = function(y){Math.pow(y, 1.1)}
    var saveIt3 = function(y){Math.pow(y, 1.1)}
    if (x % 2) {
        saveIt2(x);
    }
    else {
        saveIt3(x);
    }

   try {throw 1}
   catch(e){}
};
</script>

Setup

var perf = performance;
    var result = 0;

Teardown


    // use the result to prevent the code being thrown out
    window.saveIt(result);
  

Test runner

Ready to run.

Testing in
TestOps/sec
Date.now
result = Date.now();
ready
+new Date()
result = +new Date();
ready
performance.now()
result = performance.now()
ready
new Date().getTime()
result = new Date().getTime()
ready
new Date().valueOf()
result = new Date().valueOf()
ready
Cached performance object
result = perf.now()
ready

Revisions

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