add benchmarking
This commit is contained in:
parent
9affffeab1
commit
cad7a9972d
|
|
@ -6,7 +6,8 @@
|
|||
"dev": "vite",
|
||||
"build": "tsc --noEmit && vite build --base=/folk-canvas",
|
||||
"preview": "tsc --noEmit && vite build && vite preview",
|
||||
"types": "tsc --noEmit"
|
||||
"types": "tsc --noEmit",
|
||||
"bench": "bun run src/__tests__/bench.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/parser": "^7.26.2",
|
||||
|
|
@ -20,6 +21,7 @@
|
|||
"@types/node": "^22.10.1",
|
||||
"@webgpu/types": "^0.1.51",
|
||||
"bun-types": "^1.1.38",
|
||||
"mitata": "^1.0.20",
|
||||
"typescript": "^5.7.2",
|
||||
"vite": "^6.0.0"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,72 @@
|
|||
import { bench, run } from 'mitata';
|
||||
import { Vector } from '../common/Vector';
|
||||
|
||||
// Basic vector operations
|
||||
bench('Vector.zero()', () => {
|
||||
Vector.zero();
|
||||
});
|
||||
|
||||
bench('Vector.add', () => {
|
||||
Vector.add({ x: 1, y: 2 }, { x: 3, y: 4 });
|
||||
});
|
||||
|
||||
bench('Vector.sub', () => {
|
||||
Vector.sub({ x: 1, y: 2 }, { x: 3, y: 4 });
|
||||
});
|
||||
|
||||
bench('Vector.mult', () => {
|
||||
Vector.mult({ x: 1, y: 2 }, { x: 3, y: 4 });
|
||||
});
|
||||
|
||||
bench('Vector.scale', () => {
|
||||
Vector.scale({ x: 1, y: 2 }, 2);
|
||||
});
|
||||
|
||||
// Trigonometric operations
|
||||
bench('Vector.rotate', () => {
|
||||
Vector.rotate({ x: 1, y: 2 }, Math.PI / 4);
|
||||
});
|
||||
|
||||
bench('Vector.rotateAround', () => {
|
||||
Vector.rotateAround({ x: 1, y: 2 }, { x: 0, y: 0 }, Math.PI / 4);
|
||||
});
|
||||
|
||||
bench('Vector.angle', () => {
|
||||
Vector.angle({ x: 1, y: 2 });
|
||||
});
|
||||
|
||||
bench('Vector.angleTo', () => {
|
||||
Vector.angleTo({ x: 1, y: 2 }, { x: 3, y: 4 });
|
||||
});
|
||||
|
||||
bench('Vector.angleFromOrigin', () => {
|
||||
Vector.angleFromOrigin({ x: 1, y: 2 }, { x: 0, y: 0 });
|
||||
});
|
||||
|
||||
// Distance and magnitude operations
|
||||
bench('Vector.mag', () => {
|
||||
Vector.mag({ x: 1, y: 2 });
|
||||
});
|
||||
|
||||
bench('Vector.magSquared', () => {
|
||||
Vector.magSquared({ x: 1, y: 2 });
|
||||
});
|
||||
|
||||
bench('Vector.distance', () => {
|
||||
Vector.distance({ x: 1, y: 2 }, { x: 3, y: 4 });
|
||||
});
|
||||
|
||||
bench('Vector.distanceSquared', () => {
|
||||
Vector.distanceSquared({ x: 1, y: 2 }, { x: 3, y: 4 });
|
||||
});
|
||||
|
||||
// Normalization and interpolation
|
||||
bench('Vector.normalized', () => {
|
||||
Vector.normalized({ x: 1, y: 2 });
|
||||
});
|
||||
|
||||
bench('Vector.lerp', () => {
|
||||
Vector.lerp({ x: 1, y: 2 }, { x: 3, y: 4 }, 0.5);
|
||||
});
|
||||
|
||||
await run();
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
import { readdirSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
import { dirname } from 'path';
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
|
||||
// Get all .bench.ts files in the __tests__ directory
|
||||
const benchFiles = readdirSync(__dirname)
|
||||
.filter((file) => file.endsWith('.bench.ts'))
|
||||
.filter((file) => file !== 'bench.ts'); // Exclude this runner file
|
||||
|
||||
// Run each benchmark file
|
||||
for (const file of benchFiles) {
|
||||
console.log(`\nRunning ${file}...`);
|
||||
console.log('='.repeat(50));
|
||||
await import(`./${file}`);
|
||||
}
|
||||
Loading…
Reference in New Issue