Closure Prototype Static Performance

JavaScript performance comparison

Revision 26 of this test case created by x3cion

Preparation code

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

<script>
function Y() {
	this.s = "test1";
	this.i = 0;
	this.message = function(s) {
		this.s = this.s === "test1" ? "test2" : "test1";
	}
	this.addition = function(i, j) {
		return (this.i = ((i * 2 + j * 2) / 2) + this.i);
	}
}

function A() {
  var s = "test1",
  i = 0,
	tmpA = function() {};
	tmpA.message = function() {
			s = s === "test1" ? "test2" : "test1";
		};
  tmpA.addition = function(n, j) {
			return (i = ((n * 2 + j * 2) / 2) + i);
		};
	return tmpA;
}


function C() {
this.s = "test1";
this.i = 0;
}

C.prototype.message = function() {
		this.s = this.s === "test1" ? "test2" : "test1";
	};
C.prototype.addition = function(i, j) {
		return (this.i = ((i * 2 + j * 2) / 2) + this.i);
	};

function M() {
 var s = "test1";
 this.i = 0;
 this.message = function() {
   s = s === "test1" ? "test2" : "test1";
 };
}

M.prototype.addition = function(i, j) {
		return (this.i = ((i * 2 + j * 2) / 2) + this.i);
	};

Z = {
	s: "test1",
	i: 0,
	message: function() {
		this.s = this.s === "test1" ? "test2" : "test1";
	},
	addition: function(i, j) {
		return (this.i = ((i * 2 + j * 2) / 2) + this.i);
	}
};
	</script>
    

Preparation code output

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
Static
Z.message();
Z.addition(1, 2);
pending…
Mixed
m = new M();
m.message(),
m.addition(1, 2);
pending…
Anon (no new)
a.message();
a.addition(1, 2);
pending…
Closure (no new)
y.message();
y.addition(1, 2);
pending…
real prototype (no new)
c.message();
c.addition(1, 2);
pending…
real prototype
c = new C();
c.message();
c.addition(1, 2);
pending…
Closure
y = new Y();
y.message();
y.addition(1, 2);
pending…
Anon
a = new A();
a.message();
a.addition(1, 2);
pending…
Mixed (no new)
m.message();
m.addition(1, 2);
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