taskType=${taskType:-'CPU_INTENSIVE'}
taskSize=${taskSize:-5000}
poolSize=${poolSize:-$(nproc --all)}
-iterations=${iterations:-100000}
+numIterations=${iterations:-100000}
-echo 'Running benchmarks with pool size:' ${poolSize}', number of iterations:' ${iterations}', task type:' ${taskType} 'and task size:' ${taskSize}
+echo 'Running benchmarks with pool size:' ${poolSize}', number of iterations:' ${numIterations}', task type:' ${taskType} 'and task size:' ${taskSize}
export NODE_ENV=production
export TASK_TYPE=${taskType}
export TASK_SIZE=${taskSize}
export POOL_SIZE=${poolSize}
-export NUM_ITERATIONS=${iterations}
+export NUM_ITERATIONS=${numIterations}
case "$OSTYPE" in
darwin*)
caffeinate ./hyperfine_benchmarks.sh
import { DynamicPool } from 'node-worker-threads-pool'
-import { executeAsyncFn } from './utils.mjs'
+import { BenchmarkDefaults, executeAsyncFn } from './utils.mjs'
import functionToBench from './functions/function-to-bench.js'
-const size = parseInt(process.env.POOL_SIZE)
-const iterations = parseInt(process.env.NUM_ITERATIONS)
+const size = parseInt(process.env.POOL_SIZE) || BenchmarkDefaults.poolSize
+const numIterations =
+ parseInt(process.env.NUM_ITERATIONS) || BenchmarkDefaults.numIterations
const data = {
test: 'MYBENCH',
- taskType: process.env.TASK_TYPE,
- taskSize: parseInt(process.env.TASK_SIZE)
+ taskType: process.env.TASK_TYPE || BenchmarkDefaults.taskType,
+ taskSize: parseInt(process.env.TASK_SIZE) || BenchmarkDefaults.taskSize
}
const dynamicPool = new DynamicPool(size)
async function run () {
const promises = new Set()
- for (let i = 0; i < iterations; i++) {
+ for (let i = 0; i < numIterations; i++) {
promises.add(
dynamicPool.exec({
task: functionToBench,
import Piscina from 'piscina'
-import { executeAsyncFn } from './utils.mjs'
+import { BenchmarkDefaults, executeAsyncFn } from './utils.mjs'
-const size = parseInt(process.env.POOL_SIZE)
-const iterations = parseInt(process.env.NUM_ITERATIONS)
+const size = parseInt(process.env.POOL_SIZE) || BenchmarkDefaults.poolSize
+const numIterations =
+ parseInt(process.env.NUM_ITERATIONS) || BenchmarkDefaults.numIterations
const data = {
test: 'MYBENCH',
- taskType: process.env.TASK_TYPE,
- taskSize: parseInt(process.env.TASK_SIZE)
+ taskType: process.env.TASK_TYPE || BenchmarkDefaults.taskType,
+ taskSize: parseInt(process.env.TASK_SIZE) || BenchmarkDefaults.taskSize
}
const piscina = new Piscina({
async function run () {
const promises = new Set()
- for (let i = 0; i < iterations; i++) {
+ for (let i = 0; i < numIterations; i++) {
promises.add(piscina.run(data))
}
await Promise.all(promises)
import { DynamicThreadPool } from 'poolifier'
-import { executeAsyncFn } from './utils.mjs'
+import { BenchmarkDefaults, executeAsyncFn } from './utils.mjs'
-const size = parseInt(process.env.POOL_SIZE)
-const iterations = parseInt(process.env.NUM_ITERATIONS)
+const size = parseInt(process.env.POOL_SIZE) || BenchmarkDefaults.poolSize
+const numIterations =
+ parseInt(process.env.NUM_ITERATIONS) || BenchmarkDefaults.numIterations
const data = {
test: 'MYBENCH',
- taskType: process.env.TASK_TYPE,
- taskSize: parseInt(process.env.TASK_SIZE)
+ taskType: process.env.TASK_TYPE || BenchmarkDefaults.taskType,
+ taskSize: parseInt(process.env.TASK_SIZE) || BenchmarkDefaults.taskSize
}
const dynamicThreadPool = new DynamicThreadPool(
async function run () {
const promises = new Set()
- for (let i = 0; i < iterations; i++) {
+ for (let i = 0; i < numIterations; i++) {
promises.add(dynamicThreadPool.execute(data))
}
await Promise.all(promises)
import Tinypool from 'tinypool'
-import { executeAsyncFn } from './utils.mjs'
+import { BenchmarkDefaults, executeAsyncFn } from './utils.mjs'
-const size = parseInt(process.env.POOL_SIZE)
-const iterations = parseInt(process.env.NUM_ITERATIONS)
+const size = parseInt(process.env.POOL_SIZE) || BenchmarkDefaults.poolSize
+const numIterations =
+ parseInt(process.env.NUM_ITERATIONS) || BenchmarkDefaults.numIterations
const data = {
test: 'MYBENCH',
- taskType: process.env.TASK_TYPE,
- taskSize: parseInt(process.env.TASK_SIZE)
+ taskType: process.env.TASK_TYPE || BenchmarkDefaults.taskType,
+ taskSize: parseInt(process.env.TASK_SIZE) || BenchmarkDefaults.taskSize
}
const tinypool = new Tinypool({
async function run () {
const promises = new Set()
- for (let i = 0; i < iterations; i++) {
+ for (let i = 0; i < numIterations; i++) {
promises.add(tinypool.run(data))
}
await Promise.all(promises)
'use strict'
const WorkerNodes = require('worker-nodes')
+const { BenchmarkDefaults } = require('./utils.mjs')
-const size = parseInt(process.env.POOL_SIZE)
-const iterations = parseInt(process.env.NUM_ITERATIONS)
+const size = parseInt(process.env.POOL_SIZE) || BenchmarkDefaults.poolSize
+const numIterations =
+ parseInt(process.env.NUM_ITERATIONS) || BenchmarkDefaults.numIterations
const data = {
test: 'MYBENCH',
- taskType: process.env.TASK_TYPE,
- taskSize: parseInt(process.env.TASK_SIZE)
+ taskType: process.env.TASK_TYPE || BenchmarkDefaults.taskType,
+ taskSize: parseInt(process.env.TASK_SIZE) || BenchmarkDefaults.taskSize
}
const workerNodes = new WorkerNodes(
async function run () {
const promises = new Set()
- for (let i = 0; i < iterations; i++) {
+ for (let i = 0; i < numIterations; i++) {
promises.add(workerNodes.call.functionToBench(data))
}
await Promise.all(promises)
import workerpool from 'workerpool'
-import { executeAsyncFn } from './utils.mjs'
+import { BenchmarkDefaults, executeAsyncFn } from './utils.mjs'
-const size = parseInt(process.env.POOL_SIZE)
-const iterations = parseInt(process.env.NUM_ITERATIONS)
+const size = parseInt(process.env.POOL_SIZE) || BenchmarkDefaults.poolSize
+const numIterations =
+ parseInt(process.env.NUM_ITERATIONS) || BenchmarkDefaults.numIterations
const dataArray = [
'MYBENCH',
- process.env.TASK_TYPE,
- parseInt(process.env.TASK_SIZE)
+ process.env.TASK_TYPE || BenchmarkDefaults.taskType,
+ parseInt(process.env.TASK_SIZE) || BenchmarkDefaults.taskSize
]
const workerPool = workerpool.pool(
async function run () {
const promises = new Set()
- for (let i = 0; i < iterations; i++) {
+ for (let i = 0; i < numIterations; i++) {
promises.add(workerPool.exec('functionToBench', dataArray))
}
await Promise.all(promises)
import { ThreadPool } from 'nanothreads'
-import { executeAsyncFn } from './utils.mjs'
+import { BenchmarkDefaults, executeAsyncFn } from './utils.mjs'
import functionToBench from './functions/function-to-bench.js'
-const size = parseInt(process.env.POOL_SIZE)
-const iterations = parseInt(process.env.NUM_ITERATIONS)
+const size = parseInt(process.env.POOL_SIZE) || BenchmarkDefaults.poolSize
+const numIterations =
+ parseInt(process.env.NUM_ITERATIONS) || BenchmarkDefaults.numIterations
const data = {
test: 'MYBENCH',
- taskType: process.env.TASK_TYPE,
- taskSize: parseInt(process.env.TASK_SIZE)
+ taskType: process.env.TASK_TYPE || BenchmarkDefaults.taskType,
+ taskSize: parseInt(process.env.TASK_SIZE) || BenchmarkDefaults.taskSize
}
const threadPool = new ThreadPool({
async function run () {
const promises = new Set()
- for (let i = 0; i < iterations; i++) {
+ for (let i = 0; i < numIterations; i++) {
promises.add(threadPool.exec(data))
}
await Promise.all(promises)
import Piscina from 'piscina'
-import { executeAsyncFn } from './utils.mjs'
+import { BenchmarkDefaults, executeAsyncFn } from './utils.mjs'
-const size = parseInt(process.env.POOL_SIZE)
-const iterations = parseInt(process.env.NUM_ITERATIONS)
+const size = parseInt(process.env.POOL_SIZE) || BenchmarkDefaults.poolSize
+const numIterations =
+ parseInt(process.env.NUM_ITERATIONS) || BenchmarkDefaults.numIterations
const data = {
test: 'MYBENCH',
- taskType: process.env.TASK_TYPE,
- taskSize: parseInt(process.env.TASK_SIZE)
+ taskType: process.env.TASK_TYPE || BenchmarkDefaults.taskType,
+ taskSize: parseInt(process.env.TASK_SIZE) || BenchmarkDefaults.taskSize
}
const piscina = new Piscina({
async function run () {
const promises = new Set()
- for (let i = 0; i < iterations; i++) {
+ for (let i = 0; i < numIterations; i++) {
promises.add(piscina.run(data))
}
await Promise.all(promises)
import { FixedThreadPool } from 'poolifier'
-import { executeAsyncFn } from './utils.mjs'
+import { BenchmarkDefaults, executeAsyncFn } from './utils.mjs'
-const size = parseInt(process.env.POOL_SIZE)
-const iterations = parseInt(process.env.NUM_ITERATIONS)
+const size = parseInt(process.env.POOL_SIZE) || BenchmarkDefaults.poolSize
+const numIterations =
+ parseInt(process.env.NUM_ITERATIONS) || BenchmarkDefaults.numIterations
const data = {
test: 'MYBENCH',
- taskType: process.env.TASK_TYPE,
- taskSize: parseInt(process.env.TASK_SIZE)
+ taskType: process.env.TASK_TYPE || BenchmarkDefaults.taskType,
+ taskSize: parseInt(process.env.TASK_SIZE) || BenchmarkDefaults.taskSize
}
const fixedThreadPool = new FixedThreadPool(
async function run () {
const promises = new Set()
- for (let i = 0; i < iterations; i++) {
+ for (let i = 0; i < numIterations; i++) {
promises.add(fixedThreadPool.execute(data))
}
await Promise.all(promises)
import Tinypool from 'tinypool'
-import { executeAsyncFn } from './utils.mjs'
+import { BenchmarkDefaults, executeAsyncFn } from './utils.mjs'
-const size = parseInt(process.env.POOL_SIZE)
-const iterations = parseInt(process.env.NUM_ITERATIONS)
+const size = parseInt(process.env.POOL_SIZE) || BenchmarkDefaults.poolSize
+const numIterations =
+ parseInt(process.env.NUM_ITERATIONS) || BenchmarkDefaults.numIterations
const data = {
test: 'MYBENCH',
- taskType: process.env.TASK_TYPE,
- taskSize: parseInt(process.env.TASK_SIZE)
+ taskType: process.env.TASK_TYPE || BenchmarkDefaults.taskType,
+ taskSize: parseInt(process.env.TASK_SIZE) || BenchmarkDefaults.taskSize
}
const tinypool = new Tinypool({
async function run () {
const promises = new Set()
- for (let i = 0; i < iterations; i++) {
+ for (let i = 0; i < numIterations; i++) {
promises.add(tinypool.run(data))
}
await Promise.all(promises)
'use strict'
const WorkerNodes = require('worker-nodes')
+const { BenchmarkDefaults } = require('./utils.mjs')
-const size = parseInt(process.env.POOL_SIZE)
-const iterations = parseInt(process.env.NUM_ITERATIONS)
+const size = parseInt(process.env.POOL_SIZE) || BenchmarkDefaults.poolSize
+const numIterations =
+ parseInt(process.env.NUM_ITERATIONS) || BenchmarkDefaults.numIterations
const data = {
test: 'MYBENCH',
- taskType: process.env.TASK_TYPE,
- taskSize: parseInt(process.env.TASK_SIZE)
+ taskType: process.env.TASK_TYPE || BenchmarkDefaults.taskType,
+ taskSize: parseInt(process.env.TASK_SIZE) || BenchmarkDefaults.taskSize
}
const workerNodes = new WorkerNodes(
async function run () {
const promises = new Set()
- for (let i = 0; i < iterations; i++) {
+ for (let i = 0; i < numIterations; i++) {
promises.add(workerNodes.call.functionToBench(data))
}
await Promise.all(promises)
import workerpool from 'workerpool'
-import { executeAsyncFn } from './utils.mjs'
+import { BenchmarkDefaults, executeAsyncFn } from './utils.mjs'
-const size = parseInt(process.env.POOL_SIZE)
-const iterations = parseInt(process.env.NUM_ITERATIONS)
+const size = parseInt(process.env.POOL_SIZE) || BenchmarkDefaults.poolSize
+const numIterations =
+ parseInt(process.env.NUM_ITERATIONS) || BenchmarkDefaults.numIterations
const dataArray = [
'MYBENCH',
- process.env.TASK_TYPE,
- parseInt(process.env.TASK_SIZE)
+ process.env.TASK_TYPE || BenchmarkDefaults.taskType,
+ parseInt(process.env.TASK_SIZE) || BenchmarkDefaults.taskSize
]
const workerPool = workerpool.pool(
async function run () {
const promises = new Set()
- for (let i = 0; i < iterations; i++) {
+ for (let i = 0; i < numIterations; i++) {
promises.add(workerPool.exec('functionToBench', dataArray))
}
await Promise.all(promises)
import { StaticPool } from 'node-worker-threads-pool'
-import { executeAsyncFn } from './utils.mjs'
+import { BenchmarkDefaults, executeAsyncFn } from './utils.mjs'
import functionToBench from './functions/function-to-bench.js'
-const size = parseInt(process.env.POOL_SIZE)
-const iterations = parseInt(process.env.NUM_ITERATIONS)
+const size = parseInt(process.env.POOL_SIZE) || BenchmarkDefaults.poolSize
+const numIterations =
+ parseInt(process.env.NUM_ITERATIONS) || BenchmarkDefaults.numIterations
const data = {
test: 'MYBENCH',
- taskType: process.env.TASK_TYPE,
- taskSize: parseInt(process.env.TASK_SIZE)
+ taskType: process.env.TASK_TYPE || BenchmarkDefaults.taskType,
+ taskSize: parseInt(process.env.TASK_SIZE) || BenchmarkDefaults.taskSize
}
const staticPool = new StaticPool({
async function run () {
const promises = new Set()
- for (let i = 0; i < iterations; i++) {
+ for (let i = 0; i < numIterations; i++) {
promises.add(staticPool.exec(data))
}
await Promise.all(promises)
+import { availableParallelism } from 'poolifier'
+
export const executeAsyncFn = async fn => {
try {
await fn()
process.exit(1)
}
}
+
+export const BenchmarkDefaults = {
+ poolSize: availableParallelism(),
+ numIterations: 100000,
+ taskType: 'CPU_INTENSIVE',
+ taskSize: 5000
+}