offset vs getBoundingClientRect() (v5)

Revision 5 of this benchmark created on


Preparation HTML

<div style="position:relative;padding:20px;margin-top:12px">
<div style="position:relative;padding:40px;margin-top:12px">

<div id="mydiv">
test
<div>

</div>
</div>

Setup

var mydiv = document.getElementById('mydiv').offsetTop;
     var mydiv2 = document.getElementById('mydiv').getBoundingClientRect().top;

Test runner

Ready to run.

Testing in
TestOps/sec
offset function
document.getElementById('mydiv').offsetTop;
 
ready
getBoundingClientRect
document.getElementById('mydiv').getBoundingClientRect().top;
ready

Revisions

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