From 15e5141f463661f3dd0f17e8a9402703fddd4050 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 8 Apr 2023 15:28:03 +0200 Subject: [PATCH] refactor: switch Date.now() -> performance.now() where appropriate MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- examples/dynamicExample.js | 4 ++-- examples/fixedExample.js | 4 ++-- tests/pools/cluster/fixed.test.js | 4 ++-- tests/pools/thread/fixed.test.js | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) 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) }) -- 2.34.1