{"id":21186849,"url":"https://github.com/patrickroberts/gpcpu","last_synced_at":"2025-07-17T04:41:47.016Z","repository":{"id":36385735,"uuid":"223836982","full_name":"patrickroberts/gpcpu","owner":"patrickroberts","description":"Asynchronous Parallel Programming for TypedArray","archived":false,"fork":false,"pushed_at":"2023-01-05T01:40:58.000Z","size":667,"stargazers_count":1,"open_issues_count":12,"forks_count":0,"subscribers_count":2,"default_branch":"develop","last_synced_at":"2024-04-28T20:04:23.705Z","etag":null,"topics":["asynchronous-tasks","javascript","parallel-programming","typedarray","typescript","web-workers","worker-threads"],"latest_commit_sha":null,"homepage":"https://patrickroberts.github.io/gpcpu/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/patrickroberts.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-11-25T01:22:13.000Z","updated_at":"2020-01-31T14:59:38.000Z","dependencies_parsed_at":"2023-01-17T01:01:30.805Z","dependency_job_id":null,"html_url":"https://github.com/patrickroberts/gpcpu","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrickroberts%2Fgpcpu","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrickroberts%2Fgpcpu/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrickroberts%2Fgpcpu/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/patrickroberts%2Fgpcpu/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/patrickroberts","download_url":"https://codeload.github.com/patrickroberts/gpcpu/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243639558,"owners_count":20323511,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asynchronous-tasks","javascript","parallel-programming","typedarray","typescript","web-workers","worker-threads"],"created_at":"2024-11-20T18:26:43.684Z","updated_at":"2025-03-14T20:19:07.542Z","avatar_url":"https://github.com/patrickroberts.png","language":"TypeScript","readme":"# gpcpu\nAsynchronous Parallel Programming for TypedArray\n\n## About\n\n`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.\n\nThis significantly speeds up execution of sequential `for` loops over large typed arrays by delegating each block of execution to a concurrently running thread.\n\n## Support\n\n`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.\n\n## Install\n\n### [npm] (Recommended)\n\n```sh\nnpm i gpcpu\n```\n\n### [unpkg]\n\n```html\n\u003cscript src=\"https://unpkg.com/gpcpu\"\u003e\u003c/script\u003e\n```\n\n## Usage\n\n```js\nimport { Manager } from 'gpcpu';\n\n// uses the number of threads your hardware can run concurrently by default\nconst parallel = new Manager();\nconst fltArr = new Float64Array(100000000);\n\nconsole.time('parallel');\n\nparallel.forEach(fltArr, (subArr, localIndex, globalIndex) =\u003e {\n  subArr[localIndex] = Math.sqrt(globalIndex);\n}).then(() =\u003e {\n  // ~557ms on Intel Core i7-7700K @ 4.20GHz using 8 threads\n  console.timeEnd('parallel');\n  // use fltArr here\n});\n```\n\n## Benchmark Comparison\n\n```js\nconst fltArr = new Float64Array(100000000);\n\nconsole.time('sequential');\n\nfor (let i = 0; i \u003c fltArr.length; ++i) {\n  fltArr[i] = Math.sqrt(i);\n}\n\n// ~2564ms on Intel Core i7-7700K @ 4.20GHz\nconsole.timeEnd('sequential');\n// use fltArr here\n```\n\n## Documentation\n\nAvailable on [Github Pages].\n\n[Node.js]: https://nodejs.org\n[Web Workers]: https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API\n[Worker Threads]: https://nodejs.org/api/worker_threads.html#worker_threads_worker_threads\n[npm]: https://www.npmjs.com/package/gpcpu\n[unpkg]: https://unpkg.com\n[Github Pages]: https://patrickroberts.github.io/gpcpu/\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatrickroberts%2Fgpcpu","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpatrickroberts%2Fgpcpu","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpatrickroberts%2Fgpcpu/lists"}