-| Command | Mean [s] | Min [s] | Max [s] | Relative |
-| :----------------------------------------- | -------------: | ------: | ------: | ----------: |
-| `node dynamic-poolifier.js` | 14.335 ± 0.244 | 14.080 | 15.133 | 1.02 ± 0.02 |
-| `node fixed-poolifier.js` | 14.070 ± 0.229 | 13.783 | 14.640 | 1.00 |
-| `node dynamic-piscina.js` | 15.119 ± 0.155 | 14.973 | 15.534 | 1.07 ± 0.02 |
-| `node fixed-piscina.js` | 16.444 ± 0.314 | 16.219 | 17.152 | 1.17 ± 0.03 |
-| `node fixed-tinypool.mjs` | 16.360 ± 0.301 | 16.129 | 17.051 | 1.16 ± 0.03 |
-| `node dynamic-tinypool.mjs` | 15.319 ± 0.282 | 14.990 | 16.117 | 1.09 ± 0.03 |
-| `node dynamic-workerpool.js` | 17.021 ± 0.416 | 16.663 | 18.025 | 1.21 ± 0.04 |
-| `node fixed-workerpool.js` | 17.430 ± 0.281 | 17.190 | 18.235 | 1.24 ± 0.03 |
-| `node dynamic-node-worker-threads-pool.js` | 25.111 ± 0.267 | 24.885 | 25.908 | 1.78 ± 0.03 |
-| `node static-node-worker-threads-pool.js` | 16.958 ± 0.235 | 16.772 | 17.846 | 1.21 ± 0.03 |
-| `node threadjs.js` | 47.460 ± 2.351 | 42.898 | 53.758 | 3.37 ± 0.18 |
-| `node fixed-threadwork.js` | 16.492 ± 0.239 | 16.279 | 17.453 | 1.17 ± 0.03 |
-| `node fixed-microjob.js` | 33.609 ± 0.571 | 33.100 | 35.256 | 2.39 ± 0.06 |
-| `node dynamic-worker-nodes.js` | 16.087 ± 0.209 | 15.907 | 16.896 | 1.14 ± 0.02 |
-| `node fixed-worker-nodes.js` | 16.680 ± 0.254 | 16.480 | 17.412 | 1.19 ± 0.03 |
// IMPORT LIBRARIES
-const { DynamicPool } = require('node-worker-threads-pool')
+import { DynamicPool } from 'node-worker-threads-pool'
// FINISH IMPORT LIBRARIES
// IMPORT FUNCTION TO BENCH
-const functionToBench = require('./functions/function-to-bench')
+import functionToBench from './functions/function-to-bench.mjs'
// FINISH IMPORT FUNCTION TO BENCH
const size = parseInt(process.env.POOL_SIZE)
const iterations = parseInt(process.env.NUM_ITERATIONS)
process.exit()
}
-run()
+await run()
// IMPORT LIBRARIES
-const Piscina = require('piscina')
+import Piscina from 'piscina'
// FINISH IMPORT LIBRARIES
const size = parseInt(process.env.POOL_SIZE)
const iterations = parseInt(process.env.NUM_ITERATIONS)
}
const piscina = new Piscina({
- filename: './workers/piscina/function-to-bench-worker.js',
+ filename: './workers/piscina/function-to-bench-worker.mjs',
minThreads: size,
maxThreads: size * 3,
idleTimeout: 60000 // this is the same as poolifier default
process.exit()
}
-run()
+await run()
// IMPORT LIBRARIES
-const { DynamicThreadPool } = require('poolifier')
+import { DynamicThreadPool } from 'poolifier'
// FINISH IMPORT LIBRARIES
const size = parseInt(process.env.POOL_SIZE)
const iterations = parseInt(process.env.NUM_ITERATIONS)
const dynamicPool = new DynamicThreadPool(
size,
size * 3,
- './workers/poolifier/function-to-bench-worker.js'
+ './workers/poolifier/function-to-bench-worker.mjs'
)
async function run () {
process.exit()
}
-run()
+await run()
}
const tinypool = new Tinypool({
- filename: './workers/tinypool/function-to-bench-worker.js',
+ filename: './workers/tinypool/function-to-bench-worker.mjs',
minThreads: size,
maxThreads: size * 3,
idleTimeout: 60000 // this is the same as poolifier default
process.exit()
}
-run()
+await run()
// IMPORT LIBRARIES
-const WorkerNodes = require('worker-nodes')
+import { resolve } from 'path'
+import WorkerNodes from 'worker-nodes'
// FINISH IMPORT LIBRARIES
const size = parseInt(process.env.POOL_SIZE)
const iterations = parseInt(process.env.NUM_ITERATIONS)
}
const workerNodes = new WorkerNodes(
- require.resolve('./workers/worker-nodes/function-to-bench-worker'),
+ resolve('./workers/worker-nodes/function-to-bench-worker'),
{
minWorkers: size,
maxWorkers: size * 3,
process.exit()
}
-run()
+await run()
// IMPORT LIBRARIES
-const workerpool = require('workerpool')
+import workerpool from 'workerpool'
// FINISH IMPORT LIBRARIES
const size = parseInt(process.env.POOL_SIZE)
const iterations = parseInt(process.env.NUM_ITERATIONS)
]
const workerPool = workerpool.pool(
- './workers/workerpool/function-to-bench-worker.js',
+ './workers/workerpool/function-to-bench-worker.mjs',
{
minWorkers: size,
maxWorkers: size * 3,
process.exit()
}
-run()
+await run()
// IMPORT LIBRARIES
-const { job, start } = require('microjob')
+import { job, start } from 'microjob'
// FINISH IMPORT LIBRARIES
// IMPORT FUNCTION TO BENCH
-const functionToBench = require('./functions/function-to-bench')
+import functionToBench from './functions/function-to-bench.mjs'
// FINISH IMPORT FUNCTION TO BENCH
const size = parseInt(process.env.POOL_SIZE)
const iterations = parseInt(process.env.NUM_ITERATIONS)
process.exit()
}
-run()
+await run()
// IMPORT LIBRARIES
-const Piscina = require('piscina')
+import Piscina from 'piscina'
// FINISH IMPORT LIBRARIES
const size = parseInt(process.env.POOL_SIZE)
const iterations = parseInt(process.env.NUM_ITERATIONS)
}
const piscina = new Piscina({
- filename: './workers/piscina/function-to-bench-worker.js',
+ filename: './workers/piscina/function-to-bench-worker.mjs',
minThreads: size,
maxThreads: size,
idleTimeout: 60000 // this is the same as poolifier default
process.exit()
}
-run()
+await run()
// IMPORT LIBRARIES
-const { FixedThreadPool } = require('poolifier')
+import { FixedThreadPool } from 'poolifier'
// FINISH IMPORT LIBRARIES
const size = parseInt(process.env.POOL_SIZE)
const iterations = parseInt(process.env.NUM_ITERATIONS)
const fixedPool = new FixedThreadPool(
size,
- './workers/poolifier/function-to-bench-worker.js'
+ './workers/poolifier/function-to-bench-worker.mjs'
)
async function run () {
process.exit()
}
-run()
+await run()
// IMPORT LIBRARIES
-const threadPool = require('./pool-threadwork')
+import threadPool from './pool-threadwork'
// FINISH IMPORT LIBRARIES
const iterations = parseInt(process.env.NUM_ITERATIONS)
const data = {
process.exit()
}
-run()
+await run()
}
const tinypool = new Tinypool({
- filename: './workers/tinypool/function-to-bench-worker.js',
+ filename: './workers/tinypool/function-to-bench-worker.mjs',
minThreads: size,
maxThreads: size,
idleTimeout: 60000 // this is the same as poolifier default
process.exit()
}
-run()
+await run()
// IMPORT LIBRARIES
-const WorkerNodes = require('worker-nodes')
+import { resolve } from 'path'
+import WorkerNodes from 'worker-nodes'
// FINISH IMPORT LIBRARIES
const size = parseInt(process.env.POOL_SIZE)
const iterations = parseInt(process.env.NUM_ITERATIONS)
}
const workerNodes = new WorkerNodes(
- require.resolve('./workers/worker-nodes/function-to-bench-worker'),
+ resolve('./workers/worker-nodes/function-to-bench-worker'),
{
minWorkers: size,
maxWorkers: size,
process.exit()
}
-run()
+await run()
// IMPORT LIBRARIES
-const workerpool = require('workerpool')
+import workerpool from 'workerpool'
// FINISH IMPORT LIBRARIES
const size = parseInt(process.env.POOL_SIZE)
const iterations = parseInt(process.env.NUM_ITERATIONS)
]
const workerPool = workerpool.pool(
- './workers/workerpool/function-to-bench-worker.js',
+ './workers/workerpool/function-to-bench-worker.mjs',
{
minWorkers: size,
maxWorkers: size,
process.exit()
}
-run()
+await run()
+import crypto from 'crypto'
+import fs from 'fs'
+
/**
* The worker function to execute during pools benchmarks.
* NOTE: This function requires to be self-contained, thread-safe and re-entrant.
* @param {*} data The worker data.
* @returns {*} The result.
*/
-function functionToBench (data) {
- const crypto = require('crypto')
- const fs = require('fs')
+export default function functionToBench (data) {
const TaskTypes = {
CPU_INTENSIVE: 'CPU_INTENSIVE',
IO_INTENSIVE: 'IO_INTENSIVE'
throw new Error(`Unknown task type: ${data.taskType}`)
}
}
-
-module.exports = functionToBench
#!/usr/bin/env bash
-hyperfine --export-markdown BENCH-100000.md --min-runs 20 --prepare 'sleep 2' --warmup 2 \
- 'node dynamic-poolifier.js' \
- 'node fixed-poolifier.js' \
- 'node dynamic-piscina.js' \
- 'node fixed-piscina.js' \
+hyperfine --export-markdown BENCH-100000.md --min-runs 20 --prepare 'sleep 2' --warmup 2 --show-output \
+ 'node dynamic-poolifier.mjs' \
+ 'node fixed-poolifier.mjs' \
+ 'node dynamic-piscina.mjs' \
+ 'node fixed-piscina.mjs' \
'node fixed-tinypool.mjs' \
'node dynamic-tinypool.mjs' \
- 'node dynamic-workerpool.js' \
- 'node fixed-workerpool.js' \
- 'node dynamic-node-worker-threads-pool.js' \
- 'node static-node-worker-threads-pool.js' \
- 'node threadjs.js' \
- 'node fixed-threadwork.js' \
- 'node fixed-microjob.js' \
- 'node dynamic-worker-nodes.js' \
- 'node fixed-worker-nodes.js'
+ 'node dynamic-workerpool.mjs' \
+ 'node fixed-workerpool.mjs' \
+ 'node dynamic-node-worker-threads-pool.mjs' \
+ 'node static-node-worker-threads-pool.mjs' \
+ 'node threadjs.mjs' \
+ 'node fixed-threadwork.mjs' \
+ 'node fixed-microjob.mjs' \
+ 'node dynamic-worker-nodes.mjs' \
+ 'node fixed-worker-nodes.mjs'
+++ /dev/null
-// IMPORT LIBRARIES
-const { ThreadPool } = require('threadwork')
-// FINISH IMPORT LIBRARIES
-// IMPORT FUNCTION TO BENCH
-const functionToBench = require('./functions/function-to-bench')
-// FINISH IMPORT FUNCTION TO BENCH
-const size = parseInt(process.env.POOL_SIZE)
-
-module.exports = new ThreadPool({ task: functionToBench, size })
--- /dev/null
+// IMPORT LIBRARIES
+import { ThreadPool } from 'threadwork'
+// FINISH IMPORT LIBRARIES
+// IMPORT FUNCTION TO BENCH
+import functionToBench from './functions/function-to-bench.mjs'
+// FINISH IMPORT FUNCTION TO BENCH
+const size = parseInt(process.env.POOL_SIZE)
+
+export default new ThreadPool({ task: functionToBench, size })
// IMPORT LIBRARIES
-const { StaticPool } = require('node-worker-threads-pool')
+import { StaticPool } from 'node-worker-threads-pool'
// FINISH IMPORT LIBRARIES
// IMPORT FUNCTION TO BENCH
-const functionToBench = require('./functions/function-to-bench')
+import functionToBench from './functions/function-to-bench.mjs'
// FINISH IMPORT FUNCTION TO BENCH
const size = parseInt(process.env.POOL_SIZE)
const iterations = parseInt(process.env.NUM_ITERATIONS)
process.exit()
}
-run()
+await run()
// IMPORT LIBRARIES
-const { spawn, Worker } = require('threads')
+import { Worker, spawn } from 'threads'
// FINISH IMPORT LIBRARIES
const size = parseInt(process.env.POOL_SIZE)
const iterations = parseInt(process.env.NUM_ITERATIONS)
async function poolify () {
for (let i = 0; i < size; i++) {
const worker = await spawn(
- new Worker('./workers/threadjs/function-to-bench-worker.js')
+ new Worker('./workers/threadjs/function-to-bench-worker.mjs')
)
workers.push(worker)
}
process.exit()
}
-run()
+await run()
+++ /dev/null
-'use strict'
-const functionToBench = require('../../functions/function-to-bench')
-module.exports = functionToBench
--- /dev/null
+import functionToBench from '../../functions/function-to-bench.mjs'
+export default functionToBench
+++ /dev/null
-'use strict'
-const { ThreadWorker } = require('poolifier')
-const functionToBench = require('../../functions/function-to-bench')
-module.exports = new ThreadWorker(functionToBench)
--- /dev/null
+import { ThreadWorker } from 'poolifier'
+import functionToBench from '../../functions/function-to-bench.mjs'
+export default new ThreadWorker(functionToBench)
+++ /dev/null
-'use strict'
-const { expose } = require('threads/worker')
-const functionToBench = require('../../functions/function-to-bench')
-
-expose({
- exposedFunction (data) {
- return functionToBench(data)
- }
-})
--- /dev/null
+import { expose } from 'threads/worker'
+import functionToBench from '../../functions/function-to-bench.mjs'
+
+expose({
+ exposedFunction (data) {
+ return functionToBench(data)
+ }
+})
+++ /dev/null
-'use strict'
-const functionToBench = require('../../functions/function-to-bench')
-module.exports = functionToBench
--- /dev/null
+import functionToBench from '../../functions/function-to-bench.mjs'
+export default functionToBench
+++ /dev/null
-'use strict'
-const functionToBench = require('../../functions/function-to-bench')
-module.exports = { functionToBench }
--- /dev/null
+import functionToBench from '../../functions/function-to-bench.mjs'
+export { functionToBench }
-'use strict'
-const workerpool = require('workerpool')
-const functionToBench = require('../../functions/function-to-bench')
+import workerpool from 'workerpool'
+import functionToBench from '../../functions/function-to-bench.mjs'
function workerPoolWrapperFunctionToBench (testName, taskType, taskSize) {
return functionToBench({