Performance of Javascript timers

Benchmark created by Mateusz ★ on


Description

Different methods of getting time in JavaScript gives the different performance results in browsers. The http://jsperf.com/gettime-vs-now-0/7 clearly shows, that the winners are Date.now() (Chrome and Opera) and window.performance.now() (Firefox and Internet Explorer). By testing the overhead of declaring a function that returns either Date.now() or performance.now() it's clear that you can try to use different method depending on the browser a user uses. But it would require a browser sniffing, which is not the most elegant solution.

Setup

var perf = window.performance;
    function dateNow() {
        return Date.now();
    }
    function perfNow() {
        return perf.now();
    }

Teardown


    var t1;
  

Test runner

Ready to run.

Testing in
TestOps/sec
Date.now()
t1 = Date.now();
ready
performance.now()
t1 = perf.now();
ready
Date.now() function
t1 = dateNow();
ready
performance.now() function
t1 = perfNow();
ready

Revisions

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

  • Revision 1: published by Mateusz ★ on
  • Revision 2: published by iProDev on
  • Revision 3: published by Jiayong Ou on
  • Revision 4: published by Jiayong Ou on
  • Revision 5: published by Jiayong Ou on