testing out chaining functions

JavaScript performance comparison

Revision 2 of this test case created by Barbarrosa

Preparation code

 
<script>
Benchmark.prototype.setup = function() {
    var callbackList = [];
    for (var i; i < 100; i++) {
      callbackList.push(function() {
        return i;
      })
    }
    var iListLength = callbackList.length;
    var n = null;
};
</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
for in
for (var x in callbackList) {
  x();
}
pending…
x,n (preallocated n)
for (var x = 0; n = callbackList[x]; ++x) {
  n();
}
pending…
x,n2
for (var x = 0, n2; n2 = callbackList[x]; ++x) {
  n2();
}
pending…
x (preallocated length)
for (var x = 0; x < iListLength; x++) {
  callbackList[x]();
}
pending…
x
for (var x = 0; x < callbackList.length; x++) {
  callbackList[x]();
}
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