Buffer vs array storing data

Benchmark created on


Setup

const BUF_ITEM_SIZE = 18
const items = 80_000

const buf = Buffer.alloc(BUF_ITEM_SIZE * items)
const arr = Array.from({ length: items }).map(() => ({ a: 1, b: 2 }))

Test runner

Ready to run.

Testing in
TestOps/sec
arr
let sum = 0
for (const item of arr) {
	sum += item.a
}
ready
bufs
let sum = 0
for (let i = 0; i < items; i += 1) {
    sum += buf.readUIntLE(i * BUF_ITEM_SIZE, 4)
}
ready

Revisions

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