obj props (v3)

Revision 3 of this benchmark created on


Setup

const x = new Uint8Array(4)
const storeUint8 = (
  buff,
  n,
  start,
  len,
) => {
  // can be so much faster...
  // just specific
  for (let index = start; index < start + len; index++) {
    const byte = n & 0xff
    buff[index] = byte
    n = (n - byte) / 256
  }
}

const wrtiteUint32 = (dest, val, offset) => {
  dest[offset + 0] = val
  dest[offset + 1] = val >>>= 8
  dest[offset + 2] = val >>>= 8
}

const wrtiteUint32NoAs = (dest, val, offset) => {
  dest[offset + 0] = val
  dest[offset + 1] = val >>> 8
  dest[offset + 2] = val >>> 16
}

Test runner

Ready to run.

Testing in
TestOps/sec
store using fn
for (let i = 0; i <1e5; i++) {
storeUint8(x, 99999, 0, 3)
}
ready
store using bytes
const n = 99999
for (let i = 0; i <1e5; i++) {
x[0] = n 
x[1] = n >>> 8
x[2] = n >>> 16
}

ready
store using bytes + change in place
for (let i = 0; i <1e5; i++) {

let n = 99999
x[0] = n 
x[1] = n >>>= 8
x[2] = n >>>= 8
}
ready
store using bytes from fn
for (let i = 0; i <1e5; i++) {

wrtiteUint32(x, 99999, 0)
}
ready
fn no a
for (let i = 0; i <1e5; i++) {

wrtiteUint32NoAs(x, 99999, 0)
}
ready

Revisions

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