0

The cpu efficiency of how to use setTimeout / setInterval to calculate mobile browser?

function fn() {
    var start = new Date();
    setInterval(function () {
        var _s = new Date();
        console.info(_s - start);
        start = _s;
    }, 1000/60)
}
fn()
Thinking80s
  • 2,870
  • 3
  • 16
  • 16
  • How does it relate to `css3`? – Alvin Wong Oct 25 '12 at 11:13
  • possible duplicate (or at least related): [Are there any standards for mobile device web browsers in terms of thread sleeping?](http://stackoverflow.com/questions/10739835/are-there-any-standards-for-mobile-device-web-browsers-in-terms-of-thread-sleepi) – Bergi Oct 25 '12 at 13:27

1 Answers1

1

You can use console.time:

function someFunction(){
    console.timeEnd('someFunction timer');
    //this function's code goes here...
    console.time('someFunction timer');
}

This will give you the time your function took to execute. Is this what you needed?

Or maybe this?

var start = new Date().getTime();

//your code
var end = new Date().getTime();
var time = end - start;
alert('Execution time: ' + time);
Filipe Melo
  • 558
  • 5
  • 10