Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
cached getComputedStyle vs. getBoundingClientRect
(version: 0)
Comparing performance of:
getComputedStyle vs getBoundingClientRect
Created:
2 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<div id="foo">test</div>
Tests:
getComputedStyle
const elem = document.getElementById("foo"); const computed = getComputedStyle(elem); var i = 5000; while (i--) { getHeight(); } function getHeight() { return parseFloat(computed.height); }
getBoundingClientRect
const elem = document.getElementById("foo"); var i = 5000; while (i--) { getHeight(); } function getHeight() { return elem.getBoundingClientRect().height; }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
getComputedStyle
getBoundingClientRect
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36
Browser/OS:
Chrome 132 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
getComputedStyle
60.4 Ops/sec
getBoundingClientRect
81.3 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what is tested, compared, pros and cons of different approaches, library usage, special JavaScript features, and other considerations. **What is being tested?** Two individual test cases are being run: 1. `getComputedStyle`: This test case measures the execution time of getting the computed style of an element using the `getComputedStyle()` function. 2. `getBoundingClientRect`: This test case measures the execution time of getting the bounding rectangle of an element using the `getBoundingClientRect()` function. **Options compared** The two options being compared are: 1. Using `getComputedStyle()` to get the computed style of an element 2. Using `getBoundingClientRect()` to get the bounding rectangle of an element **Pros and cons of each approach** 1. **getComputedStyle()** * Pros: + Provides accurate measurements of CSS styles + Allows for precise control over styling * Cons: + May be slower due to additional DOM queries and calculations + May not work well with animated or dynamic content 2. **getBoundingClientRect()** * Pros: + Faster execution time compared to `getComputedStyle()` + Works well with animated or dynamic content * Cons: + May provide less accurate measurements of CSS styles + May require additional calculations for precise styling **Library usage** There is no explicit library mentioned in the benchmark definitions. However, it's likely that these functions are part of the browser's DOM API. **Special JavaScript features** None are explicitly mentioned, but it's worth noting that both `getComputedStyle()` and `getBoundingClientRect()` can be affected by browser-specific quirks or performance optimizations. **Other considerations** 1. **Browser differences**: The benchmark is run on a Chrome 126 browser on a Mac OS X 10.15.7 machine. 2. **Test setup**: Each test case involves creating an HTML element, getting its computed style using `getComputedStyle()` or bounding rectangle using `getBoundingClientRect()`, and then repeating this process 5000 times while measuring the execution time. **Alternatives** Other alternatives for measuring CSS styles or bounding rectangles might include: 1. Using a separate library like jQuery UI's `.css()` function or a third-party library like CSS-Utils. 2. Using other browser-specific APIs, such as WebKit's `layoutLayout` API (for WebKit-based browsers). 3. Implementing a custom solution using JavaScript and/or WebGL (for high-performance applications).
Related benchmarks:
window.getComputedStyle vs. getBoundingClientRect
window.getComputedStyle vs. getBoundingClientRect vs. window.getComputedStyle without getters
offsetwidth vs getBoundingClientRect
getComputedStyle vs getBoundingClientRect
window.getComputedStyle vs. getBoundingClientRect width
Comments
Confirm delete:
Do you really want to delete benchmark?