Optimizing the queue

ํ ๊ตฌํ˜„ํ•˜๊ธฐ์—์„œ ์‹ค์ œ๋กœ ๋ฐฐ์—ด์„ ์‚ฌ์šฉํ•ด์„œ ํ๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ๋ณด๋‹ค ์ตœ์ ํ™”๋ฅผ ๋งˆ์นœ ํ๋ฅผ ๋”ฐ๋กœ ๊ตฌํ˜„ํ•ด์„œ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ๋” ๋‚ซ๋‹ค๊ณ  ํ–ˆ๋‹ค.
benchmark๋ผ๋Š” ํ•จ์ˆ˜๋ฅผ ๋งŒ๋“ค์–ด์„œ Date.now()๋ฅผ ๋ถˆ๋Ÿฌ์˜ค๋ฉด ์‹œ์ž‘ ์‹œ์ ์ด ํ• ๋‹น๋˜๊ณ  enqueue๋ฉ”์„œ๋“œ๋‚˜ dequeue๋ฉ”์„œ๋“œ๋ฅผ ๊ต‰์žฅํžˆ ํฐ ์ˆ˜๋งŒํผ ํ˜ธ์ถœํ•œ๋‹ค. ์—ฐ์‚ฐ์ด ๋๋‚˜๋ฉด ๋๋‚œ ์‹œ์ ์—์„œ ์‹œ์ž‘ ์‹œ์ ์„ ๋นผ์„œ ์„ฑ๋Šฅ์„ ์ธก์ •ํ•œ๋‹ค.
function benchmark(queue, enqueue) {
    let start = Date.now();
    for (let i = 0; i < count; i++) {
        enqueue ? queue.enqueue() : queue.dequeue();
    }
    return Date.now() - start;
}
notion image