Skip to content

Commit

Permalink
adding test case for irrelevant size
Browse files Browse the repository at this point in the history
Signed-off-by: Thiago Santos <[email protected]>
  • Loading branch information
Thiago Santos committed Jun 25, 2020
1 parent 1a6df11 commit d47e978
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions test/test.queue-performance.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
})

0 comments on commit d47e978

Please sign in to comment.