Merging objects

Benchmark created on


Description

Understand what merging two objects together looks like for timing

Setup

function generateRandomString(length) {
  const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
  let result = '';
  for (let i = 0; i < length; i++) {
    result += characters.charAt(Math.floor(Math.random() * characters.length));
  }
  return result;
}

function getRandomCoordinate() {
	return {
		x: Math.random() * 400,
		y: Math.random() * 400,
		z: Math.random() * 400,
	};
}

function getRandomOrientation() {
	return {
		roll: Math.random() * 360,
		pitch: Math.random() * 360,
		yaw: Math.random() * 360,
	};
}

const SPATIAL_SO_DATA = new Array(100_000).fill("0").map(() => ({
	parent: generateRandomString(32),
	transform: {
		point: getRandomCoordinate(),
		orientation: getRandomOrientation(),
	}
}));

const CORE_SO_DATA = Array(100_000).fill("0").map(() => ({
	    /** Globally unique ID of the scene object. */
    id: generateRandomString(32),
    /** Specifies what we'll render in the scene for this scene object. */
    renderData: {
      type: "rg",
      uri: "rg/something/something",
      scalingFactor: 0.1,
      format: "STL",
    },
    color: generateRandomString(6),
    /** Optional boolean that specifies whether the scene object is selectable. Defaults to true. */
    isSelectable: true,
}));

Test runner

Ready to run.

Testing in
TestOps/sec
How fast
for (i = 0; i < SPATIAL_SO_DATA.lengthl; i++) {
	const merged = {
		...SPATIAL_SO_DATA[i],	
		...CORE_SO_DATA[i],
	};
}
ready
Ignored
const a = 1;
ready

Revisions

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