Test if Array popping without reducing array size helps anything

Benchmark created on


Setup

let source = []
for (let i = 0; i < 1000; i++) {
  source[i] = ['key' + i, 'value' + i]
}

class ArrayThing {
	constructor(arr) {
		this.arr = arr
		this.length = arr.length
	}
	push(i) {
		this.arr.push(i)
		this.length++
	}
	pop() {
		this.length--
	}
	setAt(index, value) {
		this.arr[index] = value
	}
}
class ArrayThing2 extends Array {}

Test runner

Ready to run.

Testing in
TestOps/sec
Array push / pop
let target = []
for (let i = 0; i < 1000; i++) {
  target.push(source[i])
}
for (let i = 0; i < 1000; i++) {
  target.pop()
}
for (let i = 0; i < 1000; i++) {
  target.push(source[i])
}
ready
ArrayThing push/pop
let target = new ArrayThing([])
for (let i = 0; i < 1000; i++) {
  target.push(source[i])
}
for (let i = 0; i < 1000; i++) {
  target.pop()
}
for (let i = 0; i < 1000; i++) {
  target.push(source[i])
}
ready
ArrayThing2 push/pop
let target = new ArrayThing2()
for (let i = 0; i < 1000; i++) {
  target.push(source[i])
}
for (let i = 0; i < 1000; i++) {
  target.pop()
}
for (let i = 0; i < 1000; i++) {
  target.push(source[i])
}
ready

Revisions

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