<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@v0.1.2/lib/dsDOM.js'></script>
</head>
<body>
<!-- Test Elements -->
<div id="testDiv" class="box original">Test Div</div>
<button id="testButton"><span class="spanbtn">Click Me</span></button>
<div class="container">
<div class="item">Item 1</div>
<div class="item">Item 2</div>
</div>
</body>
</html>
let dsCounter = 0, jQueryCounter = 0;
const button = document.getElementById('testButton');
for (let i = 0; i < 1000; i++) { // Simulate 1000 clicks
button.click();
}
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','.spanbtn', () => dsCounter++);
$('#testButton').on('click','.spanbtn', () => 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'});
new dsDOM(document).listen('click','#testButton', () => dsCounter++);
$(document).on('click','#testButton', () => jQueryCounter++);
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
JQuery Clone | |
dsDOM Clone | |
dsDOM event element -> child | |
jQuery event element -> child | |
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 | |
dsDOM event document -> element | |
jQuery event document -> element |
Test name | Executions per second |
---|---|
JQuery Clone | 78011.1 Ops/sec |
dsDOM Clone | 340434.7 Ops/sec |
dsDOM event element -> child | 1713778.0 Ops/sec |
jQuery event element -> child | 501784.8 Ops/sec |
dsDOM add Single class | 1385516.4 Ops/sec |
jQuery add Single class | 505399.6 Ops/sec |
dsDOM add Multiple classes | 794051.6 Ops/sec |
jQuery add Multiple classes | 252239.4 Ops/sec |
dsDOM selection | 4114659.2 Ops/sec |
Jquery selection | 728563.4 Ops/sec |
dsDOM remove element | 3272525.5 Ops/sec |
Jquery remove element | 762804.9 Ops/sec |
dsDOM CSS Manipulation | 898944.2 Ops/sec |
Jquery CSS Manipulation | 268165.0 Ops/sec |
dsDOM event document -> element | 2516110.5 Ops/sec |
jQuery event document -> element | 551252.3 Ops/sec |
In the provided benchmark, the performance of two different JavaScript libraries—dsDOM and jQuery—is compared across various common DOM manipulation tasks. The benchmark specifically evaluates their efficiency in performing cloning, event handling, class manipulation, element selection, and CSS manipulation. Each approach has its pros and cons, which we'll explore along with other considerations.
jQuery: A widely-used JavaScript library designed to simplify HTML DOM manipulation, event handling, and CSS manipulation. It provides methods that abstract away differences in browser implementations, making it easier to handle complex tasks in a way that is cross-browser compatible.
dsDOM: A less-known library that aims to provide a simpler and potentially lighter-weight alternative to jQuery for DOM manipulation. Its purpose is to handle similar tasks as jQuery but with a possibly more efficient approach for modern use cases.
Here’s a breakdown of the specific test cases and what each evaluates:
jQuery Clone vs dsDOM Clone:
Event Handling:
Adding a Single and Multiple Classes:
Element Selection:
Removing Elements:
CSS Manipulation:
querySelector
, addEventListener
, and class methods can handle most operations without the overhead of a library.In summary, this benchmark evaluates the efficacy of two libraries in performing common DOM manipulation tasks, with dsDOM generally outperforming jQuery in execution speed while also weighing considerations of ease of use, support, and project size.