Skip to content

Commit 08bf267

Browse files
authored
feat: Add a benchmark suite for vector creation (#1063)
1 parent eb9b537 commit 08bf267

File tree

3 files changed

+80
-1
lines changed

3 files changed

+80
-1
lines changed

apps/typegpu-docs/src/pages/benchmark/suites.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { TypeGPUDataModule, TypeGPUModule } from './modules';
55
import type { BenchParameterSet } from './parameter-set';
66
import { compiledWriteSuite } from './test-suites/compiled-write';
77
import { partialWriteSuite } from './test-suites/partial-write';
8+
import { vectorCreationSuite } from './test-suites/vector-creation';
89

910
export type TestIdentifier = `${string}_${string}`;
1011

@@ -39,6 +40,7 @@ export function createSuite<T extends { bench: Bench }>(
3940
export const unfilteredSuites: Record<string, Suite> = {
4041
'Partial write': partialWriteSuite,
4142
'Compiled write': compiledWriteSuite,
43+
'Vector creation': vectorCreationSuite,
4244
};
4345

4446
export function getFilteredSuites(selectedTests: TestIdentifier[]) {
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import { Bench } from 'tinybench';
2+
import type { v2u, v3f, v4i } from 'typegpu/data';
3+
import { stringifyLocator } from '../parameter-set';
4+
import { createSuite } from '../suites';
5+
6+
export const vectorCreationSuite = createSuite(
7+
({ params, d }) => {
8+
const ctx = {
9+
bench: null as unknown as Bench,
10+
d,
11+
thousandVectors: [] as (v3f | v2u | v4i)[],
12+
tenThousandVectors: [] as (v3f | v2u | v4i)[],
13+
hundredThousandVectors: [] as (v3f | v2u | v4i)[],
14+
};
15+
16+
ctx.bench = new Bench({
17+
name: stringifyLocator('typegpu', params.typegpu),
18+
time: 1000,
19+
setup: () => {
20+
ctx.thousandVectors = Array.from({ length: 1000 });
21+
ctx.tenThousandVectors = Array.from({ length: 10000 });
22+
ctx.hundredThousandVectors = Array.from({ length: 100000 });
23+
},
24+
});
25+
26+
return ctx;
27+
},
28+
{
29+
'1k vectors': (getCtx) => async () => {
30+
const { thousandVectors: container, d } = getCtx();
31+
32+
for (let i = 0; i < container.length; i++) {
33+
container[i] = d.vec3f(1, 2, 3);
34+
}
35+
36+
for (let i = 0; i < container.length; i++) {
37+
container[i] = d.vec2u(1, 2);
38+
}
39+
40+
for (let i = 0; i < container.length; i++) {
41+
container[i] = d.vec4i(1, 2, 3, 4);
42+
}
43+
},
44+
45+
'10k vectors': (getCtx) => async () => {
46+
const { tenThousandVectors: container, d } = getCtx();
47+
48+
for (let i = 0; i < container.length; i++) {
49+
container[i] = d.vec3f(1, 2, 3);
50+
}
51+
52+
for (let i = 0; i < container.length; i++) {
53+
container[i] = d.vec2u(1, 2);
54+
}
55+
56+
for (let i = 0; i < container.length; i++) {
57+
container[i] = d.vec4i(1, 2, 3, 4);
58+
}
59+
},
60+
61+
'100k vectors': (getCtx) => async () => {
62+
const { hundredThousandVectors: container, d } = getCtx();
63+
64+
for (let i = 0; i < container.length; i++) {
65+
container[i] = d.vec3f(1, 2, 3);
66+
}
67+
68+
for (let i = 0; i < container.length; i++) {
69+
container[i] = d.vec2u(1, 2);
70+
}
71+
72+
for (let i = 0; i < container.length; i++) {
73+
container[i] = d.vec4i(1, 2, 3, 4);
74+
}
75+
},
76+
},
77+
);

packages/typegpu/tsup.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default defineConfig({
1010
entry,
1111
outDir: 'dist',
1212
format: ['cjs', 'esm'],
13-
target: 'es2017',
13+
target: 'es2024',
1414
splitting: true,
1515
sourcemap: true,
1616
minify: !inDevMode,

0 commit comments

Comments
 (0)