Attempts at Constant Propagation (v3)

Revision 3 of this benchmark created on


Setup

count = 0;

function branchy(x) {
	if (x == 1) {
		count += 2;
	} else if (x == 2) {
		count += 3;
	} else if (x == 3) {
		count += 15;
	} else if (x == 4) {
		count += 18;
	} else if (x == 5) {
		count += 21;
	}
}

arr = new Int32Array(2);
arr[0] = 5;
arr[1] = 4;

closureMaker = function(val) {
	return function() { branchy(val); }
}

commonClosure1 = closureMaker(arr[0]);
commonClosure2 = closureMaker(arr[1]);

distinctClosure1 = function(val) {
	return function() { branchy(val); }
}(arr[0]);
distinctClosure2 = function(val) {
	return function() { branchy(val); }
}(arr[1]);

Test runner

Ready to run.

Testing in
TestOps/sec
Direct Call
branchy(arr[0]);
branchy(arr[1]);
ready
Common Closure
commonClosure1();
commonClosure2();
ready
Distinct Closure
distinctClosure1();
distinctClosure2();
ready

Revisions

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