Subclassing Arrays ( direct extension variations )

JavaScript performance comparison

Revision 3 of this test case created by Daniel Mendel

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  var subArr = function(){
  	var arr = [];
  	arr.rand = function(){ return Math.random() * Math.pow(100,10) };
  	arr.name = 'subclassed Array';
  	return arr;
  }
  
  var extender = function(){};
  extender.prototype.rand = function(){ return Math.random() * Math.pow(100,10) };
  extender.prototype.name = 'subclassed Array';
  
  var subArrB = function(){
  	var arr = [];
  	arr.rand = extender.prototype.rand;
  	arr.name = extender.prototype.name;
  	return arr;
  }
  

};
</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
100 x Standard
var a = new subArr();
var i = 100;
while( i-- ){
	a.push( new subArr() )
}
pending…
100 x Mediated prototype
var a = new subArrB();
var i = 100;
while( i-- ){
	a.push( new subArrB() )
}
pending…
100 x Native
var a = [];
var i = 100;
while( i-- ){
	a.push([]);
}
pending…
1,000 x Standard
var a = new subArr();
var i = 1000;
while( i-- ){
	a.push( new subArr() )
}
pending…
1,000 x Mediated Prototype
var a = new subArrB();
var i = 1000;
while( i-- ){
	a.push( new subArrB() )
}
pending…
1,000 x Native
var a = [];
var i = 1000;
while( i-- ){
	a.push([])
}
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.

0 Comments