From d47e97871c43d1caba3d6a4e47bcdad96b6a90bc Mon Sep 17 00:00:00 2001 From: Thiago Santos Date: Thu, 25 Jun 2020 10:27:32 -0300 Subject: [PATCH] adding test case for irrelevant size Signed-off-by: Thiago Santos --- test/test.queue-performance.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/test.queue-performance.js b/test/test.queue-performance.js index ae9e93b..b229415 100644 --- a/test/test.queue-performance.js +++ b/test/test.queue-performance.js @@ -30,4 +30,29 @@ describe('queue performance', () => { console.log(`Queue time: ${totalQueue[0] + totalQueue[1] / 1e9}`); expect(totalArray[0] + totalArray[1] / 1e9 > (totalQueue[0] + totalQueue[1] / 1e9) * 100).to.be.true; }); + + it('the time difference between array.shift and queue.shift should be irrelevant for small lengths', () => { + const array = []; + const queue = new Queue(); + for (let i = 1; i < 10000; i++) { + array.push(i); + queue.push(i); + } + + + const startQueue = process.hrtime(); + while (queue.length > 0) { + queue.shift(); + } + const totalQueue = process.hrtime(startQueue); + const startArray = process.hrtime(); + while (array.length > 0) { + array.shift(); + } + const totalArray = process.hrtime(startArray); + + console.log(`Array time: ${totalArray[0] + totalArray[1] / 1e9}`); + console.log(`Queue time: ${totalQueue[0] + totalQueue[1] / 1e9}`); + expect(totalArray[0] + totalArray[1] / 1e9 - (totalQueue[0] + totalQueue[1] / 1e9) < 0.001).to.be.true; + }); }) \ No newline at end of file