Skip to content

Commit

Permalink
test performance
Browse files Browse the repository at this point in the history
  • Loading branch information
marcuspoehls committed Jul 9, 2023
1 parent b7a581f commit f964e5e
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions performance/testing.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
'use strict'

const { PromisePool } = require('../dist')
const { setTimeout } = require('timers/promises')

// const batchSize = 10 * 1000
const batchSize = 50 * 1000

function createPromises (size) {
return Array.apply(null, { length: size }).map(x => exec())
}

async function exec () {
await setTimeout(1000)
}

async function run () {
console.log('Creating promises')
const promisePool = createPromises(batchSize)
console.time('PromisePool')

await PromisePool
.withConcurrency(batchSize)
.for(promisePool)
.process(async (d) => {
await d
})
console.timeEnd('PromisePool')

const promisesAll = createPromises(batchSize)
console.time('Promise.all')
await Promise.all(promisesAll)
console.timeEnd('Promise.all')
}

run()
.then(() => console.log('done'))
.catch(error => console.error('Failed to process promise pool performance', error))

0 comments on commit f964e5e

Please sign in to comment.