gpcpu
Asynchronous Parallel Programming for TypedArray
About
gpcpu
enables user-friendly parallel programming in JavaScript by defining a forEach()
function which executes a user-defined callback on multiple concurrent threads and returns a Promise
that resolves when all the results have been copied to the TypedArray provided as input.
This significantly speeds up execution of sequential for
loops over large typed arrays by delegating each block of execution to a concurrently running thread.
Support
gpcpu
provides out-of-the-box support for both browsers and Node.js by selectively using Web Workers or Worker Threads depending on the runtime environment. It also ships with typings for use in TypeScript projects.
Install
npm
npm i gpcpu
unpkg
Usage
; // uses the number of threads your hardware can run concurrently by defaultconst parallel = ;const fltArr = 100000000; console; parallel;
Benchmark Comparison
const fltArr = 100000000; console; for let i = 0; i < fltArrlength; ++i fltArri = Math; // ~2564ms on Intel Core i7-7700K @ 4.20GHzconsole;// use fltArr here
Documentation
Available on Github Pages.