migrate to vite working

This commit is contained in:
2025-02-15 09:24:56 -07:00
parent 10f6d92b7f
commit 8e6294c96f
53 changed files with 608 additions and 219 deletions

38
src/test/bench.ts Normal file
View File

@@ -0,0 +1,38 @@
import { assert } from "jsr:@std/assert";
import { describe, it } from "jsr:@std/testing/bdd";
/**
* Tests if a function can run a given number of iterations within a target frame time.
* @param fn The function to test.
* @param iterations Number of times to run the function per frame.
* @param fps Target frames per second.
*/
export function testPerformance(
fn: () => unknown,
iterations: number,
fps: number,
) {
console.log(`Performance Test - ${iterations} iterations at ${fps} FPS`);
const frameTime = 1000 / fps;
const startTime = performance.now();
for (let i = 0; i < iterations; i++) {
fn();
}
const endTime = performance.now();
const elapsed = endTime - startTime;
console.log(
`Elapsed time: ${elapsed.toFixed(2)}ms (Target: ≤${
frameTime.toFixed(2)
}ms)`,
);
assert(
elapsed <= frameTime,
`Function took too long: ${elapsed.toFixed(2)}ms (Target: ≤${
frameTime.toFixed(2)
}ms)`,
);
// });
}