Normalized vs normal update

Benchmark created on


Setup

const data = new Array(5000).fill(null).map((_,i) => ({
	name: `Name ${i}`,
	id: i,
	school: `School ${i}`,
	score: Math.random()
}))

// normalized
const dataMap = {};
data.forEach((item) => {
	dataMap[item.id] = {...item};
})
const idArray = data.map(item=>item.id);

Test runner

Ready to run.

Testing in
TestOps/sec
updating by iterating
data.map((item,i) => i%5===0 ? {...item, score: item.score *2} : item);
ready
normalized
for(let i=0; i<5000; i=i+5){
	dataMap[i] = {...dataMap[i], score: dataMap[i].score * 2};
}
ready
slow normalized
for(let i=0; i<5000; i++){
	if(i % 5 === 0){
		dataMap[i] = {...dataMap[i], score: dataMap[i].score * 2};
	}
}
ready

Revisions

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