test

Benchmark created on


Setup

a = []
b = new Float32Array(new ArrayBuffer(1024), 0, 0)

function extendTypedArray(arr, newLength) {
	const { buffer, constructor, byteOffset, length } = arr
	const newByteLength = arr.BYTES_PER_ELEMENT * newLength
	const newTotalLength = newByteLength + byteOffset

	let n = buffer.byteLength
	while (n < newTotalLength) n = Math.ceil(n * 1.5)
	return new constructor(buffer.transfer(n), byteOffset, newLength)
}

Test runner

Ready to run.

Testing in
TestOps/sec
array
a[a.length] = 4.2
b = new Float32Array(a)
ready
extendTypedArray
b = extendTypedArray(b, b.length + 1)
b[b.length - 1] = 4.2
ready

Revisions

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