Spreading vs nested for loop (v2)

Revision 2 of this benchmark created on


Preparation HTML

<script>
const caveDrawStrategyStates = {
	caveA: {
		drawPointStates: {
			drawPointA: {tonnes: 100},
			drawPointB: {tonnes: 200},
			drawPointC: {tonnes: 100},
			drawPointD: {tonnes: 200},
			drawPointE: {tonnes: 100},
			drawPointF: {tonnes: 200},
			drawPointG: {tonnes: 100},
			drawPointH: {tonnes: 200},
			drawPointI: {tonnes: 100},
			drawPointJ: {tonnes: 200},
			drawPointK: {tonnes: 100},
			drawPointL: {tonnes: 200},
			drawPointM: {tonnes: 100},
			drawPointN: {tonnes: 200},
			drawPointO: {tonnes: 100},
			drawPointP: {tonnes: 200},
			drawPointQ: {tonnes: 200},
			drawPointR: {tonnes: 100},
			drawPointS: {tonnes: 200},
			drawPointT: {tonnes: 100},
			drawPointU: {tonnes: 200},
			drawPointV: {tonnes: 100},
			drawPointW: {tonnes: 200},
			drawPointX: {tonnes: 100},
			drawPointY: {tonnes: 200},
			drawPointZ: {tonnes: 200},
		}
	},
	caveB: {
		drawPointStates: {
			drawPointE: {tonnes: 100},
			drawPointF: {tonnes: 200},
			drawPointG: {tonnes: 100},
			drawPointH: {tonnes: 200},
		}
	}		
}
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
spread em
Object.values(caveDrawStrategyStates).reduce(
        (acc, caveDrawStrategyState) => {
            acc = {...acc, ...caveDrawStrategyState.drawPointStates};
            return acc;
        },
        {}
    );
ready
for loop em
const drawPointStates = {};
for (const caveDrawStrategyState of Object.values(caveDrawStrategyStates)) {
  for (const [drawPointName, drawPointState] of Object.entries(caveDrawStrategyState.drawPointStates)) {
    drawPointStates[drawPointName] = drawPointState;
  }
}
ready

Revisions

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