<html>
•
<head>
<title>dsDOM vs jQuery Benchmark</title>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.js'></script>
<script src='https://cdn.jsdelivr.net/gh/Dianka05/dsDOM@2bd5700/lib/dsDOM.js'></script>
</head>
<body>
<!-- Test Elements -->
<div id="testDiv" class="box original">Test Div</div>
<button id="testButton">Click Me</button>
<div class="container">
<div class="item">Item 1</div>
<div class="item">Item 2</div>
</div>
</body>
</html>
/*your preparation JavaScript code goes here
To execute async code during the script preparation, wrap it as function globalMeasureThatScriptPrepareFunction, example:*/
async function globalMeasureThatScriptPrepareFunction() {
// This function is optional, feel free to remove it.
// await someThing();
}
const div = $('<div class="new">Hello</div>')
const div2 = div.clone()
const div = new dsDOM('<div class="new">Hello</div>')
const div2 = div.clone()
new dsDOM('#testButton').listen('click', null, () => dsCounter++);
$('#testButton').on('click', () => jQueryCounter++);
new dsDOM('#testDiv').addClass('highlight');
$('#testDiv').addClass('highlight');
new dsDOM('.item').addClass('active', 'selected');
$('.item').addClass('active selected');
const dsSelection = new dsDOM('.item').elements;
const jQuerySelection = $('.item');
new dsDOM('.item:first-child').remove();
$('.item:first-child').remove();
new dsDOM('#testDiv').css({color: 'red', fontSize: '20px'});
$('#testDiv').css({color: 'red', 'font-size': '20px'});
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
JQuery Clone | |
dsDOM Clone | |
dsDOM event | |
jQuery event | |
dsDOM add Single class | |
jQuery add Single class | |
dsDOM add Multiple classes | |
jQuery add Multiple classes | |
dsDOM selection | |
Jquery selection | |
dsDOM remove element | |
Jquery remove element | |
dsDOM CSS Manipulation | |
Jquery CSS Manipulation |
Test name | Executions per second |
---|---|
JQuery Clone | 80277.1 Ops/sec |
dsDOM Clone | 1197113.4 Ops/sec |
dsDOM event | 4139.0 Ops/sec |
jQuery event | 207118.3 Ops/sec |
dsDOM add Single class | 1256086.4 Ops/sec |
jQuery add Single class | 422891.0 Ops/sec |
dsDOM add Multiple classes | 740580.8 Ops/sec |
jQuery add Multiple classes | 251408.7 Ops/sec |
dsDOM selection | 3841349.0 Ops/sec |
Jquery selection | 742133.0 Ops/sec |
dsDOM remove element | 2664906.0 Ops/sec |
Jquery remove element | 767786.2 Ops/sec |
dsDOM CSS Manipulation | 1160656.9 Ops/sec |
Jquery CSS Manipulation | 294446.7 Ops/sec |
The benchmark you've provided focuses on testing the performance differences between dsDOM and jQuery, two popular JavaScript libraries for manipulating the Document Object Model (DOM). Below, I will explain what is being tested in the benchmark, compare the options, and outline the pros and cons of each approach.
dsDOM:
jQuery:
const div = $('<div class="new">Hello</div>'); const div2 = div.clone();
const div = new dsDOM('<div class="new">Hello</div>'); const div2 = div.clone();
These tests measure the speed of creating and cloning DOM elements using both libraries. The purpose is to determine which approach is faster for handling DOM element duplication.
new dsDOM('#testButton').listen('click', null, () => dsCounter++);
$('#testButton').on('click', () => jQueryCounter++);
These tests evaluate the performance of attaching event listeners to elements. Event handling performance can influence user experience, especially in applications with multiple interactive components.
Add Single Class:
new dsDOM('#testDiv').addClass('highlight');
$('#testDiv').addClass('highlight');
Add Multiple Classes:
new dsDOM('.item').addClass('active', 'selected');
$('.item').addClass('active selected');
These tests compare how quickly each library can add classes to elements, facilitating styling changes dynamically.
const dsSelection = new dsDOM('.item').elements;
const jQuerySelection = $('.item');
This evaluates how quickly each library can select elements from the DOM. Selection speed can significantly impact the performance of applications that frequently manipulate many elements.
new dsDOM('.item:first-child').remove();
$('.item:first-child').remove();
This tests the efficiency of removing elements from the DOM, which is crucial for applications that need to manipulate lists of items.
new dsDOM('#testDiv').css({color: 'red', fontSize: '20px'});
$('#testDiv').css({color: 'red', 'font-size': '20px'});
These tests assess the performance of applying CSS styles to elements, which can be frequent in responsive web design scenarios.
From the benchmark results:
dsDOM Pros:
dsDOM Cons:
jQuery Pros:
jQuery Cons:
Beyond dsDOM and jQuery, other libraries for DOM manipulation include:
In summary, developers can choose between these libraries based on their project requirements, weighing speed, size, feature set, and community support. This benchmark provides valuable insights that can guide these choices.