Constructor vs Object literal x+1

JavaScript performance comparison

Test case created by Nevallem

Preparation code


      
      <script>
Benchmark.prototype.setup = function() {
  function Test() {
  	this.x = 32768;
  	this.y = 65536;
  }
  
  Test.prototype.run = function() {
  	var i,
  		result = 0;
  
  	for ( i = 0; i < this.x; i++ ) {
  		result += this.y;
  	}
  
  	return result;
  };
  
  var test = {
  	x: 32768,
  	y: 65536
  };
  
  test.run = function() {
  	var i,
  		result = 0;
  
  	for ( i = 0; i < this.x; i++ ) {
  		result += this.y;
  	}
  
  	return result;
  };

};
</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
Constructor
( new Test() ).run();
pending…
Object literal
test.run()
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