.shift vs circular buffer

Benchmark created on


Setup

const ITER_MAX = 1E6;

const DELAY_AGG_COUNT = 100;
const arr = new Array(DELAY_AGG_COUNT)

Test runner

Ready to run.

Testing in
TestOps/sec
.shift
for (let iter = 0; iter <= ITER_MAX; ++iter) {
	if (arr.length >= DELAY_AGG_COUNT) {
		arr.shift()
	}
	arr.push(iter);
}

console.info(arr);
ready
circular buffer
idx = 0;
for (let iter = 0; iter <= ITER_MAX; ++iter) {
	arr[idx] = iter;
	++idx;
	if (idx >= DELAY_AGG_COUNT) {
		idx = 0;
	}
}
console.info(arr)
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.