<script src='https://code.jquery.com/jquery-3.6.0.min.js'></script>
const list = [];
for (let i = 0; i < 100000; i++) {
list.push(document.createElement('div'));
}
const list = [];
for (let i = 0; i < 100000; i++) {
list.push($('<div>'));
}
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
createElement | |
JQuery $ |
Test name | Executions per second |
---|---|
createElement | 9.1 Ops/sec |
JQuery $ | 3.9 Ops/sec |
Let's break down the provided benchmark and explain what is tested, compared, pros and cons of each approach, and other considerations.
What is tested on the provided JSON?
The test compares two ways to create new DOM elements: document.createElement
and $
(the jQuery dollar sign), which is used to select HTML elements. The tests are designed to measure which method is faster for creating a large number of DOM elements before insertion.
Options compared
document.createElement
: This is the native JavaScript way to create new DOM elements.$
: jQuery uses its own way of selecting and manipulating HTML elements, including creating new ones using the $
sign.Pros and cons of each approach:
document.createElement
:$
:Other considerations:
Library used:
The test uses jQuery version 3.6.0.min.js, which is a lightweight version of the library.
Special JS feature or syntax:
There are no specific JavaScript features or syntaxes mentioned in this benchmark. However, it's worth noting that other benchmarks may use features like async/await, Promises, or Web Workers to measure performance under different conditions.
Alternatives:
If you want to create a similar benchmark, you could consider the following alternatives:
HTMLElement
instead of document.createElement
Keep in mind that the specific benchmark and test cases will depend on your goals and requirements.