<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
jQuery.noConflict();
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/blissfuljs/1.0.4/bliss.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/cash/2.3.9/cash.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/Dianka05/dsDOM@latest/lib/dsDOM.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/zepto/1.2.0/zepto.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/umbrella/2.10.1/umbrella.min.js"></script>
<div id="foo">Hello World</div>
var text = document.getElementById("foo");
var text = document.getElementById("foo").textContent;
var text = document.getElementById("foo").innerHTML;
var text = $("#foo");
var text = $("#foo").text();
var text = $("#foo").html();
var text = Bliss("#foo");
var text = Bliss("#foo").textContent;
var text = jQuery("#foo");
var text = jQuery("#foo").text();
var text = jQuery("#foo").html();
const text= new dsDOM("#foo").html();
const text= new dsDOM("#foo").text();
const text= new dsDOM("#foo");
var text = Zepto("#foo");
var text = Zepto("#foo").text();
var text = Zepto("#foo").html();
var text = u("#foo");
var text = u("#foo").text();
var text = u("#foo").html();
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Vanilla Get ID | |
Vanilla Get Text | |
Vanilla Get Html | |
Cash Get ID | |
Cash Get Text | |
Cash Get Html | |
Bliss Get ID | |
Bliss Get Text | |
jQuery Get ID | |
jQuery Get Text | |
jQuery Get Html | |
dsDOM get html | |
dsDOM get text | |
dsDOM get ID | |
Zepto Get ID | |
Zepto Get Text | |
Zepto Get Html | |
Umbrella Get ID | |
Umbrella Get Text | |
Umbrella Get HTML |
Test name | Executions per second |
---|---|
Vanilla Get ID | 22975690.0 Ops/sec |
Vanilla Get Text | 7063657.0 Ops/sec |
Vanilla Get Html | 6342637.0 Ops/sec |
Cash Get ID | 3566874.5 Ops/sec |
Cash Get Text | 2718669.8 Ops/sec |
Cash Get Html | 2488740.2 Ops/sec |
Bliss Get ID | 2184293.8 Ops/sec |
Bliss Get Text | 1817807.4 Ops/sec |
jQuery Get ID | 2389748.8 Ops/sec |
jQuery Get Text | 1304158.9 Ops/sec |
jQuery Get Html | 1485033.9 Ops/sec |
dsDOM get html | 2696149.8 Ops/sec |
dsDOM get text | 2941924.5 Ops/sec |
dsDOM get ID | 4014923.8 Ops/sec |
Zepto Get ID | 2877200.8 Ops/sec |
Zepto Get Text | 783890.2 Ops/sec |
Zepto Get Html | 1747540.9 Ops/sec |
Umbrella Get ID | 496049.6 Ops/sec |
Umbrella Get Text | 476626.5 Ops/sec |
Umbrella Get HTML | 461320.0 Ops/sec |
The provided benchmark JSON tests the performance of various JavaScript libraries and vanilla JavaScript when performing DOM manipulation tasks, particularly targeting the retrieval of HTML and text content from a specific DOM element. The benchmark focuses on the following libraries:
Vanilla JavaScript: This approach uses standard JavaScript without any libraries. For example:
document.getElementById("foo")
: This retrieves the DOM element with the ID "foo".Cash: A small library that provides a jQuery-like API. It is designed to be lightweight but powerful for DOM manipulation:
$("selector")
: Quickly selects elements using jQuery-style syntax.Bliss: A micro-library designed to work with DOM manipulation while offering a simple interface. It focuses on performance and a small size:
Bliss("selector")
: Similar to Cash, it uses jQuery-like syntax for selecting elements.jQuery: A well-known and widely used library that simplifies HTML document traversal and manipulation, event handling, and AJAX. Despite being heavy, it offers a robust feature set:
$(selector)
: Provides powerful and flexible methods for DOM manipulation.dsDOM: A relatively newer library aimed at providing a minimalist and modern API for DOM manipulation. It promotes high performance with a focus on simplicity:
new dsDOM("selector")
: Similar to Bliss and Cash but with the aim of being lightweight while providing basic DOM operations.Zepto: A lightweight library that aims to be a slimmed-down version of jQuery and is particularly optimized for mobile browsers:
Umbrella: Another minimalistic library that offers a small set of features for selecting and manipulating DOM elements:
u(selector)
: It offers jQuery-like functionality in a much leaner package.The benchmark results provide a direct comparison of how well each method performs, measured in executions per second. Here are the highlights:
Vanilla JavaScript outperforms all the libraries significantly in terms of speed, especially when retrieving the ID of an element. This showcases the inherent performance advantages of directly using the browser's native API, which incurs no overhead from abstraction layers.
Cash and dsDOM show decent performance, making them suitable choices if a lightweight approach is preferred. However, they are slower than plain JavaScript.
Libraries such as Bliss, Zepto, and Umbrella have lower performance rates. The choice of these libraries could depend on the necessity for certain features and syntactical sugar they provide rather than performance alone.
jQuery, while powerful and feature-rich, is the slowest among all in this benchmark, emphasizing its higher overhead and larger size. It is still immensely popular due to its extensive ecosystem, support, and usability in legacy projects.
Vanilla JavaScript:
Cash:
Bliss:
jQuery:
dsDOM:
Zepto and Umbrella:
Aside from performance considerations, engineers might also look into modern frameworks like React, Vue.js, or Angular, which abstract DOM manipulation in a different context (i.e., reactive state management). These frameworks often optimize rendering efficiently but come with their own learning curves and overhead.
In summary, the benchmark illustrates the critical balance between performance and ease of use, demonstrating that while libraries can offer powerful abstractions and syntactic sugar, direct usage of the browser's APIs is often unmatched in raw speed. Choosing the right tool depends on the specific needs of the project, such as performance requirements, developer familiarity, and project legacy aspects.