Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
GBCR Sequential (2)
(version: 0)
Test the performance of getBoundingClientRect sequential calls.
Comparing performance of:
control vs gbcr one vs gbcr all
Created:
7 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
function createEl() { const el = document.createElement('div'); el.style.width = 100; el.style.height = 100; el.style.position = 'relative'; el.style.x = 10; el.style.y = 10; return el; } const els = [... new Array(10)].map(() => createEl()); window.els = els; els.forEach(el => document.body.appendChild(el));
Tests:
control
console.log('const');
gbcr one
console.log('const'); window.els[0].getBoundingClientRect();
gbcr all
console.log('const'); window.els.forEach(el => el.getBoundingClientRect());
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
control
gbcr one
gbcr all
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark and explain what's being tested. **Benchmark Definition** The benchmark is created using MeasureThat.net, which allows users to create and run JavaScript microbenchmarks. The benchmark definition is a JSON object that specifies the test case. In this case, there are three test cases: 1. "control": This test case simply logs the string "const" to the console. 2. "gbcr one": This test case logs the string "const" and then calls `window.els[0].getBoundingClientRect()` on the first element in the `els` array. 3. "gbcr all": This test case logs the string "const", loops through the entire `els` array, and calls `el.getBoundingClientRect()` on each element. **Options being compared** The options being compared are the performance of calling `getBoundingClientRect()` on individual elements versus looping through an array of elements and calling it on each one. Specifically: * In "gbcr one", only the first element is called. * In "gbcr all", all elements in the `els` array are called. **Pros and cons** * **"gbcr one"**: This test case may be faster because it only calls `getBoundingClientRect()` on a single element, which can reduce overhead. However, this also means that the performance difference between individual elements versus looping through an array of elements is not captured. * **"gbcr all"**: This test case captures the performance difference between calling `getBoundingClientRect()` on individual elements versus looping through an array of elements. However, "gbcr all" may be slower because it loops through the entire array and calls `getBoundingClientRect()` on each element. This can increase overhead due to function call overhead, array iteration, and DOM manipulation. **Library** The library used in this benchmark is none explicitly mentioned, but `window.els` suggests that it's using a global variable to store an array of HTML elements. The `getBoundingClientRect()` method is a standard JavaScript API that allows you to get the bounding rectangle of an element on the client-side. **Special JS feature or syntax** There are no special features or syntax used in this benchmark beyond standard JavaScript and DOM manipulation. There's also no use of modern JavaScript features like ES6 classes, async/await, or Promises. **Alternatives** Other alternatives to measure the performance difference between individual elements versus looping through an array of elements could include: * Using a library like Lodash or Ramda for array iteration * Using a different data structure, such as a Set or Map, instead of an array * Using a more efficient DOM manipulation approach, such as using `requestAnimationFrame()` to update the DOM * Using a virtual DOM or a rendering engine like React or Angular Keep in mind that these alternatives may change the behavior and performance characteristics of the benchmark, so it's essential to carefully consider the trade-offs when choosing an alternative.
Related benchmarks:
document.getElementById vs GetChildElementById
document.getElementById vs GetChildElementById
document.getElementById vs GetChildElementById
Fastest way to list children: childNodes vs children vs firstChild/nextSibling vs firstElementChild/nextElementSibling v2
Fastest way to list children: childNodes vs children vs firstChild/nextSibling vs firstElementChild/nextElementSibling v2 fixed
Comments
Confirm delete:
Do you really want to delete benchmark?