Frozen and sealed object enumeration performance (v2)

Revision 2 of this 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, sealed, noXt){
	let n = 1;
	let ret = [];
	for (let i=0; i<mult; i++){
		let obj = createObject(n);
		if (frozen)
			Object.freeze(obj);
		else if (sealed)
			Object.seal(obj);
		else if (noXt)
			Object.preventExtensions(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;
}

const m = 4;

const control = createObjects(m);
const frozen = createObjects(m, true);
const sealed = createObjects(m, false, true);
const noXt = createObjects(m, false, false, true);

Test runner

Ready to run.

Testing in
TestOps/sec
Enumerate the single own property of control object (non-frozen, non-sealed, non-extension prevented)
got = enumerateAll(control[0]);
if (got !== 1)
	throw got;
ready
Enumerate the single own property of frozen object
got = enumerateAll(frozen[0]);
if (got !== 1)
	throw got;
ready
Enumerate the single own property of sealed object
got = enumerateAll(sealed[0]);
if (got !== 1)
	throw got;
ready
Enumerate the single own property of object with extensions prevented
got = enumerateAll(noXt[0]);
if (got !== 1)
	throw got;
ready
Enumerate all 10 own properties of control object (non-frozen, non-sealed, non-extension prevented)
got = enumerateAll(control[1]);
if (got !== 10)
	throw got;
ready
Enumerate all 10 own properties of frozen object
got = enumerateAll(frozen[1]);
if (got !== 10)
	throw got;
ready
Enumerate all 10 own properties of sealed object
got = enumerateAll(sealed[1]);
if (got !== 10)
	throw got;
ready
Enumerate all 10 own properties of object with extensions prevented
got = enumerateAll(noXt[1]);
if (got !== 10)
	throw got;
ready
Enumerate all 100 own properties of control object (non-frozen, non-sealed, non-extension prevented)
got = enumerateAll(control[2]);
if (got !== 100)
	throw got;
ready
Enumerate all 100 own properties of frozen object
got = enumerateAll(frozen[2]);
if (got !== 100)
	throw got;
ready
Enumerate all 100 own properties of sealed object
got = enumerateAll(sealed[2]);
if (got !== 100)
	throw got;
ready
Enumerate all 100 own properties of object with extensions prevented
got = enumerateAll(noXt[2]);
if (got !== 100)
	throw got;
ready
Enumerate all 1000 own properties of control object (non-frozen, non-sealed, non-extension prevented)
got = enumerateAll(control[3]);
if (got !== 1000)
	throw got;
ready
Enumerate all 1000 own properties of frozen object
got = enumerateAll(frozen[3]);
if (got !== 1000)
	throw got;
ready
Enumerate all 1000 own properties of sealed object
got = enumerateAll(sealed[3]);
if (got !== 1000)
	throw got;
ready
Enumerate all 1000 own properties of object with extensions prevented
got = enumerateAll(noXt[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.