Script Preparation code:
AخA
 
function randomString() {
  const charSet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
  const max = Math.max(2, Math.floor(Math.random() * 200))
  let randomString = ''
  for (var i = 0; i < max; i++) {
    const randomPosition = Math.floor(Math.random() * charSet.length)
    randomString += charSet.substring(randomPosition, randomPosition + 1)
  }
  return randomString
}
const canvas = document.createElement('canvas')
window.context = canvas.getContext('2d')
window.data = [...Array(1000).keys()].map(randomString)
window.data.forEach((text) => {
  const div = document.createElement('div')
  div.innerHTML = text
  document.body.appendChild(div)
})
Tests:
  • offsetWidth

     
    [...document.body.children].forEach(node => {
      node.offsetWidth
    })
  • getBoundingClientRect

     
    [...document.body.children].forEach(node => {
      node.getBoundingClientRect().width
    })
  • canvas

     
    window.data.forEach(text => {
      window.context.measureText(text)
    })
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    offsetWidth
    getBoundingClientRect
    canvas

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 4 years ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:80.0) Gecko/20100101 Firefox/80.0
Firefox 80 on Mac OS X 10.15
View result in a separate tab
Test name Executions per second
offsetWidth 3770.9 Ops/sec
getBoundingClientRect 1386.9 Ops/sec
canvas 26.8 Ops/sec