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);
  • Access offset properties directly

     
    const { offsetWidth, offsetHeight, offsetTop } = el;
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    getBoundingClientRect
    getLocalDOMRect
    Access offset properties directly

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 8 minutes ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36
Chrome 135 on Windows
View result in a separate tab
Test name Executions per second
getBoundingClientRect 652922.8 Ops/sec
getLocalDOMRect 80458.5 Ops/sec
Access offset properties directly 240281.2 Ops/sec