Skip to content

Commit 1acfea5

Browse files
committed
test: add FES-off benchmark for p5.Graphics.set()
Mirrors the minified build, where FES is excluded from the bundle, so the _getRGBA cost can be measured without Zod validation on top of it. Sets and restores the flag inside the timed callback to avoid leaking into other benchmark files sharing the process.
1 parent 6067a9e commit 1acfea5

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { bench, describe } from 'vitest';
2+
import p5 from '../../src/app';
3+
4+
// Mirrors the minified build, where FES is excluded from the bundle.
5+
// Set inside the timed callback so the flag does not leak into other
6+
// benchmark files sharing this process.
7+
describe('p5.Graphics.set() performance (FES off)', () => {
8+
const options = { iterations: 10, time: 2000 };
9+
const W = 100;
10+
const H = 100;
11+
const FRAMES = 50;
12+
13+
bench(
14+
'set() hot loop',
15+
async () => {
16+
const previousFES = p5.disableFriendlyErrors;
17+
p5.disableFriendlyErrors = true;
18+
19+
try {
20+
let myp5;
21+
new p5(function (p) {
22+
p.setup = function () {
23+
myp5 = p;
24+
};
25+
});
26+
await vi.waitFor(() => {
27+
if (myp5 === undefined) throw new Error('not ready');
28+
});
29+
30+
const buf = myp5.createGraphics(W, H);
31+
const col = myp5.color(255, 0, 0);
32+
33+
for (let f = 0; f < FRAMES; f++) {
34+
for (let y = 0; y < H; y++) {
35+
for (let x = 0; x < W; x++) {
36+
buf.set(x, y, col);
37+
}
38+
}
39+
}
40+
41+
myp5.remove();
42+
} finally {
43+
p5.disableFriendlyErrors = previousFES;
44+
}
45+
},
46+
options
47+
);
48+
});

0 commit comments

Comments
 (0)