<script
src="https://code.jquery.com/jquery-3.6.0.min.js"
integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4="
crossorigin="anonymous"></script>
const el = $(`
<div>
<label class="clickAndCollect-label" id="click-and-collect">
<div class="clickAndCollect-input-container">
<input class="clickAndCollect-input" type="checkbox" value="click-and-collect">
<span class="clickAndCollect-label-text">Entregarme el pedido hasta mi vehiculo</span>
</div>
</label>
</div>
`);
$('body').append(el);
range = document.createRange();
var documentFragment = range.createContextualFragment(`
<div>
<label class="clickAndCollect-label" id="click-and-collect">
<div class="clickAndCollect-input-container">
<input class="clickAndCollect-input" type="checkbox" value="click-and-collect">
<span class="clickAndCollect-label-text">Entregarme el pedido hasta mi vehiculo</span>
</div>
</label>
</div>
`);
document.body.appendChild(documentFragment);
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Jquery | |
Contextual Fragment |
Test name | Executions per second |
---|---|
Jquery | 4594.7 Ops/sec |
Contextual Fragment | 1344.3 Ops/sec |
Let's break down the provided benchmark definition and explain what's being tested, compared, and their pros and cons.
What is being tested?
The benchmark measures the performance of two approaches:
What are being compared?
The benchmark compares the performance of:
$()
function.document.createRange().createContextualFragment()
and then appending it to the DOM.Options being compared:
$()
function to create a new HTML element, which is then appended to the DOM.document.createRange().createContextualFragment()
, and then appends it to the DOM.Pros and Cons of each approach:
Library used:
The benchmark uses jQuery 3.6.0, which is a popular and widely-used library for JavaScript development.
Special JS feature or syntax:
There are no special features or syntax used in this benchmark that would require specific knowledge of advanced JavaScript concepts.
Other alternatives:
If you're looking for alternative approaches to create HTML elements or manipulate the DOM, some options include:
document.createElement()
and appendChild()
.Keep in mind that the choice of approach depends on your specific use case, performance requirements, and personal preference as a developer.