<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.js'></script>
let element = $(`<div><a id="tr_1" data-target="tr_5" aria-controls="tr_6">
<svg id="tr_2"></svg>
<span id="tr_3"></span>
<div id="tr_4" data-target="tr_7">
</div>
</div>`);
let element = $($.parseHTML(`<div><a id="tr_1" data-target="tr_5" aria-controls="tr_6">
<svg id="tr_2"></svg>
<span id="tr_3"></span>
<div id="tr_4" data-target="tr_7">
</div>
</div>`));
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
without parse | |
with parseHTML |
Test name | Executions per second |
---|---|
without parse | 77300.2 Ops/sec |
with parseHTML | 9871.5 Ops/sec |
Let's break down the provided benchmark definition and test cases.
Benchmark Definition
MeasureThat.net is a website that allows users to create and run JavaScript microbenchmarks. The provided JSON represents a benchmark definition, which includes:
Individual Test Cases
The benchmark includes two individual test cases:
let element = $(`<div><a id="tr_1" data-target="tr_5" aria-controls="tr_6">\r\n <svg id="tr_2"></svg>\r\n <span id="tr_3"></span>\r\n <div id="tr_4" data-target="tr_7">\r\n </div>\r\n </div>`);
This test case uses a direct DOM creation approach, creating an element using the jQuery $
function without parsing any HTML.
let element = $($.parseHTML(`<div><a id="tr_1" data-target="tr_5" aria-controls="tr_6">\r\n <svg id="tr_2"></svg>\r\n <span id="tr_3"></span>\r\n <div id="tr_4" data-target="tr_7">\r\n </div>\r\n </div>`));
This test case uses the $.parseHTML()
method to parse an HTML string before creating the element using jQuery.
Options Compared
The benchmark is comparing two options:
$(element)
without parsing HTML.$($.parseHTML(element))
with parsing HTML.Pros and Cons of Each Approach:
Other Considerations
Alternatives
Other alternatives could include:
These alternatives would depend on specific requirements, constraints, and performance goals for each use case.