sssssssssssssss

JavaScript performance comparison

Revision 2 of this test case created

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
a
var defer = (function(){
  //wrapped in IIFE to provide a scope for deferreds and wrap
  var running = false;
  var deferreds = [function(){alert(1)},function(){alert(2)}];
  function wrap(func){
    return function(){
      func();
      var next = deferreds.shift();
      if(next){
        setTimeout(wrap(next),0);
      }else{
        running = false;
      }
    }
  }
  return function(func){
    if(running){
      deferreds.push(func);
    }else{
      setTimeout(wrap(func),0);
      running = true;
    }
  }
})()
pending…
b
function inOrderTimeout(/* func1, [func2, func3, ...funcN,] timeout */) {
    var id, args = arguments, numToRun = args.length - 1;
    /*if (numToRun < 1) {
        throw new Error('You did not provide at least 1 function to run for inOrderTimeout().\nCorrect syntax is as follows:\n\ninOrderTimeout(func1, [func2, func3, ...funcN] timeout)');
        return;
    }*/

    var currentFunc = 0, timeout = args[numToRun]; //array index is the same as the number of functions to run
    /*if (typeof timeout !== 'number' && timeout !== '0' && +timeout === 0 || timeout === Infinity || timeout === -Infinity || +timeout !== +timeout) {
        throw new Error('You did not provide a valid number, or it was equal to positive or negative Infinity.  Only integers and string representations of integers (without anything else in it) are permitted.');
        return;
    }*/

    (function caller(func, timeout) {
        if (currentFunc > numToRun - 1) {
            clearTimeout(id);
            return;
        }
        id = setTimeout(function () {
            func();
            caller(args[++currentFunc], timeout);
        }, Math.floor(timeout));
    }(args[currentFunc], timeout));
}
inOrderTimeout(function(){alert(1)},function(){alert(2)},0)
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