singular and plural function comparison

JavaScript performance comparison

Test case created by keville

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var widget = {
  
    typeAForOne: function (item) {
      this.doSomethingWithItem(item);
    },
  
    typeAForMany: function (items) {
      for (var i = 0, count = items.length; i < count; i++) {
        this.typeAForOne(items[i]);
      }
    },
  
    typeBForOne: function (item) {
      this.typeBForMany([item]);
    },
  
    typeBForMany: function (items) {
      for (var i = 0, count = items.length; i < count; i++) {
        this.doSomethingWithItem(items[i]);
      }
    },
  
    doSomethingWithItem: function (item) {
      item && item.value;
    }
  };
  var items = [];
  var itemCount = 100;
  while (itemCount--) {
    items.push({value:itemCount});
  }

};
</script>

Test runner

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

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
type A
widget.typeAForOne({value:1});
widget.typeAForMany(items);
pending…
type B
widget.typeBForOne({value:1});
widget.typeBForMany(items);
pending…
foreach A
widget.doSomethingWithItem({value:1});
items.forEach(function (item) {
  widget.doSomethingWithItem(item);
});
pending…
foreach B
widget.doSomethingWithItem({value:1});
items.forEach(widget.doSomethingWithItem, widget);
pending…

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

Compare results of other browsers

0 Comments