desctructuring assignment

Benchmark created by Norman on


Setup

const n = 1000 * 1000
  const ary = [2, 3]
  const obj = {a: 2, b: 3}
  const f_ary = Object.freeze([2, 3])
  const f_obj = Object.freeze({a: 2, b: 3})
  let x = 0

Test runner

Ready to run.

Testing in
TestOps/sec
classic array indexing
for (let i = 0; i < n; i++) {
  x += ary[0] + ary[1]
}
ready
array destructuring
for (let i = 0; i < n; i++) {
  const [a0, a1] = ary
  x += a0 + a1
}
ready
classic object keys
for (let i = 0; i < n; i++) {
  x += obj.a + obj.b
}
ready
object desctructuring
for (let i = 0; i < n; i++) {
  const {a, b} = obj
  x += a + b
}
ready
object desctructuring with renaming
for (let i = 0; i < n; i++) {
  const {a: a0, b: a1} = obj
  x += a0 + a1
}
ready
classic (frozen) array index
for (let i = 0; i < n; i++) {
  x += f_ary[0] + f_ary[1]
}
ready
(frozen) array destructuring
for (let i = 0; i < n; i++) {
  const [a0, a1] = ary
  x += a0 + a1
}
ready
(frozen) object destructuring with renaming
for (let i = 0; i < n; i++) {
  const {a: a0, b: a1} = f_obj
  x += a0 + a1
}
ready
(frozen) object keys
for (let i = 0; i < n; i++) {
  x += f_obj.a + f_obj.b
}
ready
(frozen) object destructuring
for (let i = 0; i < n; i++) {
  const {a, b} = f_obj
  x += a + b
}
ready

Revisions

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