const el = document.createElement('div');
document.documentElement.appendChild(el);
const fragment = document.createDocumentFragment();
const el = document.createElement('div');
const heading = document.createElement('h1');
heading.innerText = 'Heading';
el.appendChild(heading);
fragment.appendChild(el);
document.documentElement.appendChild(fragment);
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
inner | |
fragment |
Test name | Executions per second |
---|---|
inner | 1006273.0 Ops/sec |
fragment | 257976.2 Ops/sec |
Let's dive into the world of MeasureThat.net!
What is tested on the provided JSON?
The provided JSON represents two JavaScript microbenchmarks. The benchmarks are designed to measure the performance of adding elements to the DOM using different approaches.
document.documentElement
.DocumentFragment
, appending elements to it, and then appending the fragment to the document.documentElement
.Options compared
The two options being compared are:
document.documentElement
(Inner benchmark).DocumentFragment
, appending elements to it, and then appending the fragment to the document.documentElement
(Fragment benchmark).Pros and Cons of each approach:
Inner Benchmark
Pros:
Cons:
Fragment Benchmark
Pros:
Cons:
Library usage:
In both benchmarks, no specific library is used. The DocumentFragment
class is a built-in JavaScript API.
Special JS feature or syntax:
There are no special features or syntax being tested in these benchmarks. They are purely focused on measuring the performance of different DOM appending approaches.
Other alternatives:
If you were to create additional benchmarks, you could consider testing other approaches, such as:
Keep in mind that the specific approach you choose will depend on your goals and requirements.
Benchmark preparation code:
The provided JSON includes two benchmark preparation codes:
const el = document.createElement('div');
document.documentElement.appendChild(el);
const fragment = document.createDocumentFragment();
const el = document.createElement('div');
const heading = document.createElement('h1');
heading.innerText = 'Heading';
el.appendChild(heading);
fragment.appendChild(el);
document.documentElement.appendChild(fragment);
Note that the fragment benchmark creates a DocumentFragment
and appends elements to it, which is then appended to the document.documentElement
.