frozen-object-enumeration-performance

Benchmark created on


Setup

function createObject(n){
	let ret = {};
	for (let i=0; i<n; i++)
		ret["item"+i] = i;
	return ret;
}

function createObjects(mult, frozen){
	let n = 1;
	let ret = [];
	for (let i=0; i<mult; i++){
		let obj = createObject(n);
		if (frozen)
			Object.freeze(obj);
		ret.push(obj);
		if (n===1)
			n=10;
		else
			n*=10;
	}
	return ret;
}

function enumerateAll(obj){
	let n=0;
	for (let key in obj)
		n++;
	return n;
}

let m = 4;

let nonFrozenObjects = createObjects(m, false);
let frozenObjects = createObjects(m, true);

Test runner

Ready to run.

Testing in
TestOps/sec
Enumerate the single own property of non-frozen object
got = enumerateAll(nonFrozenObjects[0])
if (got !== 1)
	throw got
ready
Enumerate the single own property of frozen object
got = enumerateAll(frozenObjects[0])
if (got !== 1)
	throw got
ready
Enumerate all 10 own properties of non-frozen object
got = enumerateAll(nonFrozenObjects[1])
if (got !== 10)
	throw got
ready
Enumerate all 10 own properties of frozen object
got = enumerateAll(frozenObjects[1])
if (got !== 10)
	throw got
ready
Enumerate all 100 own properties of non-frozen object
got = enumerateAll(nonFrozenObjects[2])
if (got !== 100)
	throw got
ready
Enumerate all 100 own properties of frozen object
got = enumerateAll(frozenObjects[2])
if (got !== 100)
	throw got
ready
Enumerate all 1000 own properties of non-frozen object
got = enumerateAll(nonFrozenObjects[3])
if (got !== 1000)
	throw got
ready
Enumerate all 1000 own properties of frozen object
got = enumerateAll(frozenObjects[3])
if (got !== 1000)
	throw got
ready

Revisions

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