Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
offsetwidth-vs-outerwidth
(version: 0)
Comparing performance of:
jquery vs native
Created:
8 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> <div id="imba" style="margin: 10px;"></div> window.template = "<div style='width: 20px;'></div><div style='width: 20px;'></div><div style='width: 20px;'></div><div style='width: 20px;'></div><div style='width: 20px;'></div><div style='width: 20px;'></div><div style='width: 20px;'></div><div style='width: 20px;'></div><div style='width: 20px;'></div><div style='width: 20px;'></div><div style='width: 20px;'></div><div style='width: 20px;'></div><div style='width: 20px;'></div><div style='width: 20px;'></div><div style='width: 20px;'></div>";
Tests:
jquery
$('#imba').html(window.template).outerWidth(true);
native
var imba = document.getElementById('imba'); var m = document.createDocumentFragment(); m.innerHTML += window.template; imba.appendChild(m) imba.offsetWidth;
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
jquery
native
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:129.0) Gecko/20100101 Firefox/129.0
Browser/OS:
Firefox 129 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
jquery
253735.0 Ops/sec
native
700076.4 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down what's being tested in this benchmark. **Overview** The benchmark compares the performance of two approaches to measure the width of an HTML element: `offsetWidth` and `outerWidth`. The test is designed to simulate a scenario where the width of an element is being calculated, likely for layout or positioning purposes. **Approaches Compared** There are two individual test cases: 1. **jQuery Approach**: This approach uses jQuery's `outerWidth()` method to measure the width of the HTML element. 2. **Native Approach**: This approach measures the width of the HTML element using native JavaScript methods: * `document.getElementById('imba')` gets a reference to the element with ID `imba`. * `document.createDocumentFragment()` creates a new document fragment. * The fragment's `innerHTML` property is set to the template string, which is defined in the `Html Preparation Code`. * The fragment is then appended to the `imba` element. * Finally, the `offsetWidth` property of the `imba` element is accessed. **Pros and Cons** 1. **jQuery Approach**: * Pros: Easy to use, well-established library with good performance. * Cons: Adds extra overhead due to jQuery's initialization and parsing of the template string. 2. **Native Approach**: * Pros: No additional dependencies or overhead. * Cons: Requires more manual effort and DOM manipulation. **Other Considerations** * The benchmark is running on a desktop platform with Firefox 129. * The test cases are designed to measure the width of an element with a fixed template string, which may not reflect real-world usage scenarios where templates can vary in complexity. **Library Used** The jQuery library is used in the `jQuery Approach` test case. It provides a convenient way to manipulate and query DOM elements, but also adds some overhead due to its internal workings. **Special JS Feature/Syntax** There isn't any special JavaScript feature or syntax being used in this benchmark. The focus is on comparing two approaches to measure an element's width. **Alternatives** If you wanted to modify this benchmark to compare other approaches, you could consider: * Using a different library, such as React or Angular. * Implementing a custom width calculation function using native JavaScript methods. * Adding additional complexity to the template string to simulate real-world scenarios.
Related benchmarks:
clientWidth vs offsetWidth vs window.getComputedStyle
offsetWidth vs closest
offsetwidth vs getBoundingClientRect
clientWidth vs offsetWidth vs scrollWidth
offsetWidth / offsetHeight vs. getBoundingClientRect() vs. clientWidth / clientHeight
Comments
Confirm delete:
Do you really want to delete benchmark?