<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"><script>
<script>
jQuery.noConflict();
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/blissfuljs/1.0.6/bliss.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/cash/8.1.0/cash.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();
--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 |
Test name | Executions per second |
---|---|
Vanilla Get ID | 2479795.2 Ops/sec |
Vanilla Get Text | 1350241.2 Ops/sec |
Vanilla Get Html | 1557483.2 Ops/sec |
Cash Get ID | 1072532.2 Ops/sec |
Cash Get Text | 802505.9 Ops/sec |
Cash Get Html | 838719.9 Ops/sec |
Bliss Get ID | 902054.9 Ops/sec |
Bliss Get Text | 774122.8 Ops/sec |
jQuery Get ID | 732151.1 Ops/sec |
jQuery Get Text | 503185.2 Ops/sec |
jQuery Get Html | 611399.9 Ops/sec |
Measuring the performance of different JavaScript libraries and vanilla code is crucial for understanding the trade-offs involved in choosing the right tool for a project.
Benchmark Overview
The provided benchmark tests eight scenarios: four that involve retrieving HTML elements using each library (Vanilla, Cash, Bliss, and jQuery), with two specific methods within each scenario. The goal is to determine which approach offers the best performance, considering factors such as execution speed, DOM query efficiency, and overall code complexity.
Options Compared
Pros and Cons
Performance Comparison
The benchmark results show that the order of execution speed is generally:
However, when using class selectors or attribute queries, the performance gap between libraries widens, with Cash and BlissfulJS consistently outperforming vanilla JavaScript.
Takeaways
When choosing a library for your project:
Keep in mind that performance differences can be significant for complex DOM queries, so thorough benchmarking is essential to ensure your specific use case meets the chosen library's capabilities.