X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=benchmarks%2Fversus-external-pools%2Ffixed-threadwork.js;fp=benchmarks%2Fversus-external-pools%2Ffixed-threadwork.js;h=dfba6c00f645ccd46b27d8b26513643212a82794;hb=7f6850931df7ba1410c8c167ab03b2f089bc32dd;hp=0000000000000000000000000000000000000000;hpb=412c9105b678133f3897fb524fd8f694388b86c0;p=poolifier.git diff --git a/benchmarks/versus-external-pools/fixed-threadwork.js b/benchmarks/versus-external-pools/fixed-threadwork.js new file mode 100644 index 00000000..dfba6c00 --- /dev/null +++ b/benchmarks/versus-external-pools/fixed-threadwork.js @@ -0,0 +1,25 @@ +// 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 = process.env.POOL_SIZE +const iterations = process.env.NUM_ITERATIONS +const data = { + test: 'MYBENCH', + taskType: process.env['TASK_TYPE'] +} + +const threadPool = new ThreadPool({ task: functionToBench, size: size }) + +async function run () { + const promises = [] + for (let i = 0; i < iterations; i++) { + promises.push(threadPool.run(data)) + } + await Promise.all(promises) + process.exit() +} + +run()