frozen-function-performance

Benchmark created on


Setup

function namedFunc(n){
	return n*2;
}
function namedFuncFrozen(n){
	return n*2;
}
Object.freeze(namedFuncFrozen);

const anonFunc = function(n){
	return n*2;
};
const anonFuncFrozen = function(n){
	return n*2;
};
Object.freeze(anonFuncFrozen);

const closure = (n) => n*2;
const closureFrozen = (n) => n*2;
Object.freeze(closureFrozen);

const N = 100000;

Test runner

Ready to run.

Testing in
TestOps/sec
Run N times a non-frozen named function
for (let i=0; i<N; i++){
	const res = namedFunc(i);
	if (res !== 2*i){
		throw res;
	}
}
ready
Run N times a frozen named function
for (let i=0; i<N; i++){
	const res = namedFuncFrozen(i);
	if (res !== 2*i){
		throw res;
	}
}
ready
Run N times a non-frozen anon function
for (let i=0; i<N; i++){
	const res = anonFunc(i);
	if (res !== 2*i){
		throw res;
	}
}
ready
Run N times a frozen anon function
for (let i=0; i<N; i++){
	const res = anonFuncFrozen(i);
	if (res !== 2*i){
		throw res;
	}
}
ready
Run N times a non-frozen closure function
for (let i=0; i<N; i++){
	const res = closure(i);
	if (res !== 2*i){
		throw res;
	}
}
ready
Run N times a frozen closure function
for (let i=0; i<N; i++){
	const res = closureFrozen(i);
	if (res !== 2*i){
		throw res;
	}
}
ready

Revisions

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