Browser-side GPU sorting
Run Bitonic and Radix sort implementations through WebGPU compute shaders from a small TypeScript API.
Sort Uint32Array workloads in the browser, inspect the implementation, and benchmark on your own hardware.
import { GPUContext, BitonicSorter } from 'webgpu-sorting';
// Initialize WebGPU context
const gpu = new GPUContext();
await gpu.initialize();
// Create sorter
const sorter = new BitonicSorter(gpu);
// Sort data on GPU
const data = new Uint32Array([5, 2, 8, 1, 9, 3, 7, 4, 6, 0]);
const { sortedData } = await sorter.sort(data);
console.log(sortedData); // [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]GPU sorting becomes advantageous when:
Use the interactive demo to measure the crossover point on your own hardware instead of relying on fixed benchmark claims.
graph TB
subgraph CPU["CPU Side"]
A[Input Array] --> B[Generate Data]
B --> C[Create GPU Buffer]
end
subgraph GPU["GPU Compute Shader"]
D[Read Buffer] --> E[Bitonic/Radix Sort]
E --> F[Parallel Passes]
F --> G[Write Sorted Buffer]
end
subgraph Output
G --> H[Read Back to CPU]
H --> I[Validation & Timing]
end
C --> DLearn more in the Architecture documentation.