Generate HTML and get reference to element : DOMParser + querySelectorAll vs document.createElement (version: 1)
We want to build HTMLElements and get reference to some of them in an object named controller. Here we say we want reference to elements with an 'id'.<br>
<br>
We test two different methods :<br>
- Create elements from HTML string using DOMParser and use querySelectorAll to build controller<br>
- Create elements from createElement method and build controller from them<br>
<br>
Here we also put the generated DOM in a fragment because we want to be able to append generated DOM to any element
Comparing performance of: DOMParser + querySelectorAll vs document.createElement
Memory measurements supported only in Chrome.
For precise memory measurements Chrome must be launched with --enable-precise-memory-info flag.
More information: Monitoring JavaScript Memory
Test case name
Result
DOMParser + querySelectorAll
document.createElement
Fastest:N/A
Slowest:N/A
Latest run results:
Run details: (Test run date:
2 years ago)
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36