Frozen objects

Benchmark created on


Description

Checks if objects that were Object.freeze()ed are faster when accessing properties

Setup

const obj_unfrozen = {};
const obj_frozen = {};
for(let i = 'a'.charCodeAt(); i <= 'z'.charCodeAt(); i ++){
	for(let j = 'A'.charCodeAt(); j <= 'Z'.charCodeAt(); j ++){
		const k = String.fromCharCode(i, j);
		obj_unfrozen[k] = obj_frozen[k] = i * j;
	}
}
Object.freeze(obj_frozen);

Test runner

Ready to run.

Testing in
TestOps/sec
Normal object
let total = 0;
for(let i = 0; i < 10_000; i ++){
	for(const k in obj_unfrozen){
		total += obj_unfrozen[k];
	}
}
console.log(total);
ready
Frozen object
let total = 0;
for(let i = 0; i < 10_000; i ++){
	for(const k in obj_frozen){
		total += obj_frozen[k];
	}
}
console.log(total);
ready

Revisions

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