HTML Preparation code:
AخA
 
1
<div id="el" style="transform: rotateZ(45deg)">
2
  <h2>Lorem ipsum dolor sit amet</h2>
3
</div>
Script Preparation code:
x
 
function getLocalDOMRect(el) {
  let offsetTop = 0;
  let offsetLeft = 0;
  const width = el.offsetWidth;
  const height = el.offsetHeight;
  while (el instanceof HTMLElement) {
    offsetTop += el.offsetTop;
    offsetLeft += el.offsetLeft;
    el = el.offsetParent;
  }
  return new DOMRect(offsetLeft, offsetTop, width, height);
}
const el = document.getElementById("el");
Tests:
  • getBoundingClientRect

     
    const { left, right, top, bottom } = el.getBoundingClientRect();
  • getLocalDOMRect

     
    const { left, right, top, bottom } = getLocalDOMRect(el);
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    getBoundingClientRect
    getLocalDOMRect

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: one year ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:120.0) Gecko/20100101 Firefox/120.0
Firefox 120 on Windows
View result in a separate tab
Test name Executions per second
getBoundingClientRect 594546.4 Ops/sec
getLocalDOMRect 324191.6 Ops/sec