X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=benchmarks%2Fversus-external-pools%2Ffunctions%2Ffunction-to-bench.js;h=2f75d143330a07adb22ff9b7bcbc8a9862ca1d55;hb=6bd72cd09232827a710b41952254cab597664247;hp=0c9738e62282d1486ea57141332761a0fd9705e9;hpb=9f7e7a99ea7dfa6f2fb3c2e0e025b85cfdd4e22e;p=poolifier.git diff --git a/benchmarks/versus-external-pools/functions/function-to-bench.js b/benchmarks/versus-external-pools/functions/function-to-bench.js index 0c9738e6..2f75d143 100644 --- a/benchmarks/versus-external-pools/functions/function-to-bench.js +++ b/benchmarks/versus-external-pools/functions/function-to-bench.js @@ -1,14 +1,35 @@ +const fs = require('fs') +const { + WorkerFunctions, + executeWorkerFunction + // eslint-disable-next-line n/no-unpublished-require +} = require('../../benchmarks-utils') + +const TaskTypes = { + CPU_INTENSIVE: 'CPU_INTENSIVE', + IO_INTENSIVE: 'IO_INTENSIVE' +} + module.exports = function (data) { - if ( data.taskType === 'CPU_INTENSIVE' ) { - // CPU Intensive task - for (let i = 0; i <= 5000; i++) { - const o = { - a: i + data = data || {} + data.taskType = data.taskType || TaskTypes.CPU_INTENSIVE + data.taskSize = data.taskSize || 5000 + const benchmarksFilePath = '/tmp/poolifier-benchmarks' + switch (data.taskType) { + case TaskTypes.CPU_INTENSIVE: + // CPU intensive task + data.function = data.function || WorkerFunctions.jsonIntegerSerialization + executeWorkerFunction(data) + return { ok: 1 } + case TaskTypes.IO_INTENSIVE: + // IO intensive task + for (let i = 0; i < data.taskSize; i++) { + fs.writeFileSync(benchmarksFilePath, i.toString(), 'utf8') + fs.readFileSync(benchmarksFilePath, 'utf8') + fs.unlinkSync(benchmarksFilePath) } - JSON.stringify(o) - } - return { ok: 1 } - } else { - throw new Error('Please specify the task type') + return { ok: 1 } + default: + throw new Error(`Unknown task type: ${data.taskType}`) } }