<div id="test">test</div>
var test_n = '123px';
var _style = window.getComputedStyle(document.getElementById('test'));
document.getElementById('test').offsetwidth;
document.getElementById('test').getBoundingClientRect().width;
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
offsetwidth | |
getBoundingClientRect |
Test name | Executions per second |
---|---|
offsetwidth | 5084659.5 Ops/sec |
getBoundingClientRect | 586340.8 Ops/sec |
Let's dive into the world of MeasureThat.net and explore what's being tested in this benchmark.
What is being tested?
The provided JSON represents two individual test cases, each testing a specific JavaScript property:
offsetwidth
(also known as offsetWidth
)getBoundingClientRect
These properties relate to the dimensions of HTML elements on a web page.
Options compared:
In this benchmark, we have only two options being compared:
a. Using document.getElementById('test').offsetWidth
b. Using document.getElementById('test').getBoundingClientRect().width
Let's examine both approaches:
Approach 1: offsetWidth
Approach 2: getBoundingClientRect().width
Library usage
In this benchmark, no libraries are explicitly mentioned or used.
Special JS feature/syntax
There is no special JavaScript feature or syntax being tested in this benchmark. Both approaches rely on standard JavaScript methods for accessing HTML elements' properties.
Other alternatives
While not directly related to the specific test cases, other alternatives for measuring element dimensions might include:
width
or margin
) directlywindow.getComputedStyle()
(similar to Approach 1)In conclusion, MeasureThat.net is testing the performance difference between two common approaches for accessing an HTML element's width: using offsetWidth
and getBoundingClientRect().width
. The benchmark highlights the trade-offs between speed, support, and overhead associated with each method.