Skip to content

Commit c2255b9

Browse files
authored
chore(functions): Add unwrap() benchmark (#1663)
1 parent 6bcbb5c commit c2255b9

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

benchmarks/benchmark.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,48 @@ import { VERSION } from '@gltf-transform/core';
1212
*/
1313

1414
const argv = process.argv;
15+
1516
const parseFlag = (flag: string, value: string): string => {
1617
if (!value || value.startsWith('-')) {
1718
throw new Error(`Usage: ${flag} <value>`);
1819
}
1920
return value;
2021
};
22+
2123
const flags = {
2224
filter: argv.includes('--filter') ? parseFlag('--filter', argv[argv.indexOf('--filter') + 1]) : false,
2325
past: argv.includes('--past'),
2426
table: argv.includes('--table'),
2527
report: argv.includes('--report') ? parseFlag('--report', argv[argv.indexOf('--report') + 1]) : false,
2628
reportVersion: argv.includes('--report-version'),
2729
print: argv.includes('--print'),
30+
help: argv.includes('--help') || argv.includes('-h'),
2831
};
2932

33+
if (flags.help) {
34+
console.log(
35+
`
36+
Usage: yarn bench [options]
37+
38+
Execution:
39+
--filter <pattern>: runs only benchmarks matching <pattern>
40+
--past: skip running benchmarks, show historical output only
41+
42+
Display:
43+
--print: show historical results for all benchmarks
44+
--table: show detailed report for current benchmark run only
45+
46+
History:
47+
--report <version>: append run to history as <version>, default to 'dev'
48+
--report-version: append run to history as current npm version
49+
50+
Miscellaneous:
51+
--help, -h: display help and exit
52+
`.trim(),
53+
);
54+
process.exit(0);
55+
}
56+
3057
/******************************************************************************
3158
* CREATE BENCHMARK SUITE
3259
*/

benchmarks/tasks/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { tasks as disposeTasks } from './dispose.bench.js';
66
import { tasks as flattenTasks } from './flatten.bench.js';
77
import { tasks as joinTasks } from './join.bench.js';
88
import { tasks as quantizeTasks } from './quantize.bench.js';
9+
import { tasks as unwrapTasks } from './unwrap.bench.js';
910
import { tasks as weldTasks } from './weld.bench.js';
1011

1112
export const tasks: Task[] = [
@@ -16,5 +17,6 @@ export const tasks: Task[] = [
1617
...flattenTasks,
1718
...joinTasks,
1819
...quantizeTasks,
20+
...unwrapTasks,
1921
...weldTasks,
2022
];

benchmarks/tasks/unwrap.bench.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { Document } from '@gltf-transform/core';
2+
import { unwrap } from '@gltf-transform/functions';
3+
import { createTorusKnotPrimitive } from '@gltf-transform/test-utils';
4+
import { Task } from '../constants';
5+
import { LOGGER } from '../utils';
6+
import * as watlas from 'watlas';
7+
8+
let _document: Document;
9+
10+
export const tasks: Task[] = [
11+
[
12+
'unwrap',
13+
async () => {
14+
await _document.transform(unwrap({ watlas, overwrite: true, groupBy: 'scene' }));
15+
},
16+
{
17+
beforeAll: async () => watlas.Initialize(),
18+
beforeEach: () => void (_document = createDocument(10, 10, 8)), // ~100 vertices / prim
19+
},
20+
],
21+
];
22+
23+
function createDocument(primCount: number, radialSegments: number, tubularSegments: number): Document {
24+
const document = new Document().setLogger(LOGGER);
25+
26+
const scene = document.createScene();
27+
for (let i = 0; i < primCount; i++) {
28+
const prim = createTorusKnotPrimitive(document, { radialSegments, tubularSegments });
29+
const mesh = document.createMesh().addPrimitive(prim);
30+
const node = document.createNode().setMesh(mesh);
31+
scene.addChild(node);
32+
}
33+
34+
return document;
35+
}

0 commit comments

Comments
 (0)