<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js'></script>
<script>
var $jq1124 = $.noConflict(true);
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
var $jq224 = $.noConflict(true);
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
var $jq331 = $.noConflict(true);
</script>
<div>
<ul id="menu">
<li class="menu-item">1</li>
<li class="menu-item">2</li>
<li class="menu-item">3</li>
<li class="menu-item">4</li>
</ul>
</div>
function tests($) {
$(".menu-item").eq(2).closest("ul").css({
"background-color": "red"
}).parent().css({
"border": "1px solid blue"
}).end().end().remove();
}
tests($jq1124);
tests($jq224);
tests($jq331);
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
$jq1124 | |
$jq224 | |
$jq331 |
Test name | Executions per second |
---|---|
$jq1124 | 148182.4 Ops/sec |
$jq224 | 222190.4 Ops/sec |
$jq331 | 211534.3 Ops/sec |
Let's dive into the world of JavaScript microbenchmarks on MeasureThat.net.
Benchmark Overview
The provided benchmark measures the execution speed of different jQuery versions (1.9.1, 1.11.3, and 3.5.1) in a specific test case.
Test Case
The test case is a simple HTML page that uses jQuery to manipulate an unordered list (<ul>
) element. The script preparation code defines a function tests
that takes a jQuery object as an argument. Within this function:
.menu-item.eq(2)
and sets its closest parent's background color to red.The test case is executed three times with different jQuery versions: 1.9.1, 1.11.3, and 3.5.1. Each execution is wrapped in a $.noConflict(true)
function to ensure that only one instance of jQuery is used per execution.
Options Compared
In this benchmark, we have three main options being compared:
Each option has its pros and cons:
Library and Purpose
The $.noConflict(true)
function is used to prevent conflicts between different versions of jQuery in the same document. This function returns a new version of jQuery that does not interfere with the original one, ensuring that only one instance of jQuery is used per execution.
Special JS Feature or Syntax (None)
There are no special JavaScript features or syntaxes being tested in this benchmark.
Alternatives
If you want to create similar benchmarks on MeasureThat.net, here's what you can do:
$.noConflict(true)
function if needed to prevent conflicts between different versions of jQuery.By creating custom benchmarks, you can help improve the accuracy of JavaScript microbenchmarking results and contribute to the understanding of performance differences between various JavaScript versions and libraries.