Skip to content

Instantly share code, notes, and snippets.

@greggman
Last active November 17, 2025 09:14
Show Gist options
  • Select an option

  • Save greggman/776ed19ec60fa86e08882fd1d8beb8a7 to your computer and use it in GitHub Desktop.

Select an option

Save greggman/776ed19ec60fa86e08882fd1d8beb8a7 to your computer and use it in GitHub Desktop.
WebGPU: Lots of resources
/*bug-in-github-api-content-can-not-be-empty*/
/*bug-in-github-api-content-can-not-be-empty*/
async function main() {
const adapter = await navigator.gpu.requestAdapter();
const device = await adapter.requestDevice();
const kNumPerStep = 128 * 1024;
let count = 0;
for (;;) {
const startTime = performance.now();
for (let i = 0; i < kNumPerStep; ++i) {
const buffer = device.createBuffer({size: 16, usage: GPUBufferUsage.STORAGE});
buffer.destroy();
}
device.queue.submit([]);
await device.queue.onSubmittedWorkDone();
const endTime = performance.now();
const duration = endTime - startTime;
count += kNumPerStep;
console.log(`count: ${count.toString().padEnd(10)}, duration: ${duration.toFixed(8)}ms, time per creation: ${(duration / kNumPerStep).toFixed(8)}ms`);
}
}
main();
{"name":"WebGPU: Lots of resources","settings":{},"filenames":["index.html","index.css","index.js"]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment