<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.slim.min.js"><script>
<script>jQuery.noConflict();</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/sprint/0.9.2/sprint.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/cash/6.0.1/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 = jQuery("#foo");
var text = jQuery("#foo").text();
var text = jQuery("#foo").html();
var text = Sprint("#foo");
var text = Sprint("#foo").text();
var text = Sprint("#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 | |
jQuery Get ID | |
jQuery Get Text | |
jQuery Get HTML | |
Sprint Get ID | |
Sprint Get Text | |
Sprint Get HTML |
Test name | Executions per second |
---|---|
Vanilla Get ID | 7162240.5 Ops/sec |
Vanilla Get Text | 5626761.0 Ops/sec |
Vanilla Get HTML | 5711456.0 Ops/sec |
Cash Get ID | 7456331.5 Ops/sec |
Cash Get Text | 7264184.0 Ops/sec |
Cash Get HTML | 7231329.5 Ops/sec |
jQuery Get ID | 7250292.5 Ops/sec |
jQuery Get Text | 3474722.2 Ops/sec |
jQuery Get HTML | 3361445.8 Ops/sec |
Sprint Get ID | 8945377.0 Ops/sec |
Sprint Get Text | 4582723.5 Ops/sec |
Sprint Get HTML | 4070969.0 Ops/sec |
Let's dive into the explanation of what's being tested in this benchmark.
Benchmark Definition
The benchmark is designed to compare the execution speeds of four JavaScript libraries: Vanilla (native JavaScript), Cash, jQuery, and Sprint. Each library is used to retrieve different properties from an HTML element with the id "foo".
Options Compared
The following options are compared:
document.getElementById()
or element.getPropertyValue()
.Test Cases
Each test case retrieves different properties from the HTML element:
id
propertyinnerHTML
propertytextContent
propertyThe benchmark measures the execution speed of each library for each test case, providing a detailed comparison of their performance.
Interpretation
The results suggest that Cash and Sprint are significantly faster than jQuery and Vanilla in terms of execution speed. This is likely due to their optimized implementations and focus on micro-optimizations.
Cash appears to be the fastest overall, followed closely by Sprint. jQuery falls in between, with Vanilla being the slowest.
Keep in mind that these results may vary depending on the specific use case and the environment in which the benchmark is run.