feat: add nanothreads to external pools benchmark
authorJérôme Benoit <jerome.benoit@sap.com>
Thu, 6 Jul 2023 18:44:20 +0000 (20:44 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Thu, 6 Jul 2023 18:44:20 +0000 (20:44 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
.vscode/settings.json
benchmarks/versus-external-pools/fixed-nanothreads.mjs [new file with mode: 0644]
benchmarks/versus-external-pools/hyperfine_benchmarks.sh
benchmarks/versus-external-pools/package.json
benchmarks/versus-external-pools/pnpm-lock.yaml

index 867b65ff6268e39989d1e2b1a120dea4c17e204b..002ad7d119cd70c8b57a716a6a7aa8c12f47ff05 100644 (file)
@@ -24,6 +24,7 @@
     "microtime",
     "mochawesome",
     "MYBENCH",
+    "nanothreads",
     "nocombine",
     "nproc",
     "octocat",
diff --git a/benchmarks/versus-external-pools/fixed-nanothreads.mjs b/benchmarks/versus-external-pools/fixed-nanothreads.mjs
new file mode 100644 (file)
index 0000000..4f589e2
--- /dev/null
@@ -0,0 +1,30 @@
+// IMPORT LIBRARIES
+import { ThreadPool } from 'nanothreads'
+// FINISH IMPORT LIBRARIES
+// IMPORT FUNCTION TO BENCH
+import functionToBench from './functions/function-to-bench.js'
+// FINISH IMPORT FUNCTION TO BENCH
+const size = parseInt(process.env.POOL_SIZE)
+const iterations = parseInt(process.env.NUM_ITERATIONS)
+const data = {
+  test: 'MYBENCH',
+  taskType: process.env.TASK_TYPE,
+  taskSize: parseInt(process.env.TASK_SIZE)
+}
+
+const threadPool = new ThreadPool({
+  task: functionToBench,
+  count: size
+})
+
+async function run () {
+  const promises = new Set()
+  for (let i = 0; i < iterations; i++) {
+    promises.add(threadPool.exec(data))
+  }
+  await Promise.all(promises)
+  // eslint-disable-next-line n/no-process-exit
+  process.exit()
+}
+
+await run()
index 67d25af3623cf582b8ef9068a436e0199e4b6b69..594eb446d6d281c984192fc1da9fb9e673faf521 100755 (executable)
@@ -13,3 +13,4 @@ hyperfine --export-markdown BENCH-100000.md --min-runs 20 --prepare 'sleep 5' --
   'node fixed-worker-nodes.js' \
   'node dynamic-node-worker-threads-pool.mjs' \
   'node static-node-worker-threads-pool.mjs' \
+  'node fixed-nanothreads.mjs'
index 245cca370198d43e9af402adea7bf8c82e51da9e..6d3a9926ba98d536e3c062f75ec72c4015ce0274 100644 (file)
     "test": "echo \"Error: no test specified\" && exit 1"
   },
   "dependencies": {
+    "nanothreads": "0.3.7",
     "node-worker-threads-pool": "1.5.1",
     "piscina": "4.0.0",
     "poolifier": "2.6.8",
-    "tinypool": "0.6.0",
+    "tinypool": "0.7.0",
     "worker-nodes": "2.6.0",
     "workerpool": "6.4.0"
   }
index 08f2d5c8c9256369858ebef465e152fd54265dad..3224f6ffb5c80587b1defc428e9278564809a941 100644 (file)
@@ -5,6 +5,9 @@ settings:
   excludeLinksFromLockfile: false
 
 dependencies:
+  nanothreads:
+    specifier: 0.3.7
+    version: 0.3.7
   node-worker-threads-pool:
     specifier: 1.5.1
     version: 1.5.1
@@ -15,8 +18,8 @@ dependencies:
     specifier: 2.6.8
     version: 2.6.8
   tinypool:
-    specifier: 0.6.0
-    version: 0.6.0
+    specifier: 0.7.0
+    version: 0.7.0
   worker-nodes:
     specifier: 2.6.0
     version: 2.6.0
@@ -76,6 +79,10 @@ packages:
       isarray: 1.0.0
     dev: false
 
+  /nanothreads@0.3.7:
+    resolution: {integrity: sha512-l/gbxnQBeMGspLoa+JKhqDrsBtqMW4G5ElsEgbVigR5gl6IBHzBjpM7URGeu0UQN4k7DK0o+J3GmHgaXv+aDQw==}
+    dev: false
+
   /nice-napi@1.0.2:
     resolution: {integrity: sha512-px/KnJAJZf5RuBGcfD+Sp2pAKq0ytz8j+1NehvgIGFkvtvFrDM3T8E4x/JJODXK9WZow8RRGrbA9QQ3hs+pDhA==}
     os: ['!win32']
@@ -121,8 +128,8 @@ packages:
     requiresBuild: true
     dev: false
 
-  /tinypool@0.6.0:
-    resolution: {integrity: sha512-FdswUUo5SxRizcBc6b1GSuLpLjisa8N8qMyYoP3rl+bym+QauhtJP5bvZY1ytt8krKGmMLYIRl36HBZfeAoqhQ==}
+  /tinypool@0.7.0:
+    resolution: {integrity: sha512-zSYNUlYSMhJ6Zdou4cJwo/p7w5nmAH17GRfU/ui3ctvjXFErXXkruT4MWW6poDeXgCaIBlGLrfU6TbTXxyGMww==}
     engines: {node: '>=14.0.0'}
     dev: false