diff --git a/examples/tests/stress-multi-level.ts b/examples/tests/stress-multi-level.ts new file mode 100644 index 00000000..f149a913 --- /dev/null +++ b/examples/tests/stress-multi-level.ts @@ -0,0 +1,89 @@ +/* + * If not stated otherwise in this file or this component's LICENSE file the + * following copyright and licenses apply: + * + * Copyright 2023 Comcast Cable Communications Management, LLC. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { type INode } from '@lightningjs/renderer'; +import logo from '../assets/lightning.png'; +import type { ExampleSettings } from '../common/ExampleSettings.js'; + +const randomIntBetween = (from: number, to: number) => + Math.floor(Math.random() * (to - from + 1) + from); + +export default async function ({ + renderer, + testRoot, + perfMultiplier, +}: ExampleSettings) { + // create nodes + const numOuterNodes = 100 * perfMultiplier; + const nodes: INode[] = []; + let totalNodes = 0; + + const bg = renderer.createNode({ + width: 1920, + height: 1080, + color: 0xff1e293b, + parent: testRoot, + }); + + for (let i = 0; i < numOuterNodes; i++) { + const container = renderer.createNode({ + x: Math.random() * 1920, + y: Math.random() * 1080, + parent: bg, + }); + const node = renderer.createNode({ + width: 505, + height: 101, + src: logo, + parent: container, + }); + + nodes.push(container); + totalNodes += 2; + } + + console.log( + `Created ${numOuterNodes} outer nodes with another node nested inside. Total nodes: ${totalNodes}`, + ); + + // create 100 animations + const animate = () => { + nodes.forEach((node) => { + node + .animate( + { + x: randomIntBetween(20, 1740), + y: randomIntBetween(20, 900), + rotation: Math.random() * Math.PI, + }, + { + duration: 3000, + easing: 'ease-out', + loop: true, + stopMethod: 'reverse', + }, + ) + .start(); + }); + }; + + animate(); + + // setInterval(animate, 3000); +} diff --git a/examples/tests/stress-multi-texture.ts b/examples/tests/stress-multi-texture.ts new file mode 100644 index 00000000..1d9b4793 --- /dev/null +++ b/examples/tests/stress-multi-texture.ts @@ -0,0 +1,92 @@ +/* + * If not stated otherwise in this file or this component's LICENSE file the + * following copyright and licenses apply: + * + * Copyright 2023 Comcast Cable Communications Management, LLC. + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { type INode } from '@lightningjs/renderer'; +import logo from '../assets/lightning.png'; +import robot from '../assets/robot/robot.png'; + +import type { ExampleSettings } from '../common/ExampleSettings.js'; + +const randomIntBetween = (from: number, to: number) => + Math.floor(Math.random() * (to - from + 1) + from); + +export default async function ({ + renderer, + testRoot, + perfMultiplier, +}: ExampleSettings) { + // create nodes + const numOuterNodes = 100 * perfMultiplier; + const nodes: INode[] = []; + + const bg = renderer.createNode({ + width: 1920, + height: 1080, + color: 0xff1e293b, + parent: testRoot, + }); + + for (let i = 0; i < numOuterNodes; i++) { + const node = renderer.createNode({ + x: Math.random() * 1920, + y: Math.random() * 1080, + ...(i % 2 === 0 + ? { + width: 505, + height: 101, + src: logo, + } + : { + width: 140, + height: 140, + src: robot, + }), + parent: bg, + }); + + nodes.push(node); + } + + console.log(`Created ${numOuterNodes} nodes with alternating textures`); + + // create animations + const animate = () => { + nodes.forEach((node) => { + node + .animate( + { + x: randomIntBetween(20, 1740), + y: randomIntBetween(20, 900), + rotation: Math.random() * Math.PI, + }, + { + duration: 3000, + easing: 'ease-out', + loop: true, + stopMethod: 'reverse', + }, + ) + .start(); + }); + }; + + animate(); + + // setInterval(animate, 3000); +} diff --git a/examples/tests/stress.ts b/examples/tests/stress-single-level.ts similarity index 92% rename from examples/tests/stress.ts rename to examples/tests/stress-single-level.ts index 54b137f4..56fd968c 100644 --- a/examples/tests/stress.ts +++ b/examples/tests/stress-single-level.ts @@ -30,6 +30,7 @@ export default async function ({ perfMultiplier, }: ExampleSettings) { // create 100 nodes + const numOuterNodes = 100 * perfMultiplier; const nodes: INode[] = []; const bg = renderer.createNode({ @@ -39,7 +40,7 @@ export default async function ({ parent: testRoot, }); - for (let i = 0; i < 100 * perfMultiplier; i++) { + for (let i = 0; i < numOuterNodes; i++) { const node = renderer.createNode({ width: 505, height: 101, @@ -52,6 +53,8 @@ export default async function ({ nodes.push(node); } + console.log(`Created ${numOuterNodes} nodes with the same texture`); + // create 100 animations const animate = () => { nodes.forEach((node) => {