https://github.com/agentcooper/node-worker-threads-map-example
Example of mapping an array using workers.
https://github.com/agentcooper/node-worker-threads-map-example
nodejs threads workers
Last synced: about 1 month ago
JSON representation
Example of mapping an array using workers.
- Host: GitHub
- URL: https://github.com/agentcooper/node-worker-threads-map-example
- Owner: agentcooper
- Created: 2020-06-11T11:02:41.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-06-11T11:19:45.000Z (about 6 years ago)
- Last Synced: 2025-01-13T05:29:58.530Z (over 1 year ago)
- Topics: nodejs, threads, workers
- Language: JavaScript
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Example of mapping an array using [workers](https://nodejs.org/api/worker_threads.html).
To run make sure you're using Node version >=12.
```
~/node-worker-threads-map-example % node index.js
[
2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22,
24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44,
46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66,
68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88,
90, 92, 94, 96, 98, 100
]
Computation: 9488.254ms
```
```
~/node-worker-threads-map-example % node index-without-workers.js
[
2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22,
24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44,
46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66,
68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88,
90, 92, 94, 96, 98, 100
]
Computation: 28258.634ms
```