From: Jérôme Benoit Date: Sat, 8 Apr 2023 13:28:03 +0000 (+0200) Subject: refactor: switch Date.now() -> performance.now() where appropriate X-Git-Tag: v2.4.5~14 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=15e5141f463661f3dd0f17e8a9402703fddd4050;p=poolifier.git refactor: switch Date.now() -> performance.now() where appropriate Signed-off-by: Jérôme Benoit --- diff --git a/examples/dynamicExample.js b/examples/dynamicExample.js index e1d9b503..1b7391d7 100644 --- a/examples/dynamicExample.js +++ b/examples/dynamicExample.js @@ -9,7 +9,7 @@ const pool = new DynamicThreadPool(10, 20, './yourWorker.js', { pool.emitter.on(PoolEvents.full, () => poolFull++) pool.emitter.on(PoolEvents.busy, () => poolBusy++) -const start = Date.now() +const start = performance.now() const iterations = 1000 for (let i = 1; i <= iterations; i++) { pool @@ -17,7 +17,7 @@ for (let i = 1; i <= iterations; i++) { .then(() => { resolved++ if (resolved === iterations) { - console.log('Time taken is ' + (Date.now() - start)) + console.log('Time taken is ' + (performance.now() - start)) console.log('The pool was full for ' + poolFull + ' times') return console.log('The pool was busy for ' + poolBusy + ' times') } diff --git a/examples/fixedExample.js b/examples/fixedExample.js index d10c2062..3f103ca5 100644 --- a/examples/fixedExample.js +++ b/examples/fixedExample.js @@ -7,7 +7,7 @@ const pool = new FixedThreadPool(15, './yourWorker.js', { }) pool.emitter.on(PoolEvents.busy, () => poolBusy++) -const start = Date.now() +const start = performance.now() const iterations = 1000 for (let i = 1; i <= iterations; i++) { pool @@ -15,7 +15,7 @@ for (let i = 1; i <= iterations; i++) { .then(() => { resolved++ if (resolved === iterations) { - console.log('Time taken is ' + (Date.now() - start)) + console.log('Time taken is ' + (performance.now() - start)) return console.log('The pool was busy for ' + poolBusy + ' times') } return null diff --git a/tests/pools/cluster/fixed.test.js b/tests/pools/cluster/fixed.test.js index 908acbfe..b9c7d676 100644 --- a/tests/pools/cluster/fixed.test.js +++ b/tests/pools/cluster/fixed.test.js @@ -115,9 +115,9 @@ describe('Fixed cluster pool test suite', () => { it('Verify that async function is working properly', async () => { const data = { f: 10 } - const startTime = Date.now() + const startTime = performance.now() const result = await asyncPool.execute(data) - const usedTime = Date.now() - startTime + const usedTime = performance.now() - startTime expect(result).toStrictEqual(data) expect(usedTime).toBeGreaterThanOrEqual(2000) }) diff --git a/tests/pools/thread/fixed.test.js b/tests/pools/thread/fixed.test.js index a42b5d37..cf5c3175 100644 --- a/tests/pools/thread/fixed.test.js +++ b/tests/pools/thread/fixed.test.js @@ -119,9 +119,9 @@ describe('Fixed thread pool test suite', () => { it('Verify that async function is working properly', async () => { const data = { f: 10 } - const startTime = Date.now() + const startTime = performance.now() const result = await asyncPool.execute(data) - const usedTime = Date.now() - startTime + const usedTime = performance.now() - startTime expect(result).toStrictEqual(data) expect(usedTime).toBeGreaterThanOrEqual(2000) })