<script src="//ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<label for="pseudo">Pseudo</label><input type="text" name="pseudo" id="pseudo">
let pseudo = document.querySelector("#pseudo");
pseudo.value="aaa"
let saisie = pseudo.value;
if(saisie.length < 5){
pseudo.style.border = "2px solid red";
}else{
pseudo.style.border = "2px solid green";
}
let pseudo = $("#pseudo");
pseudo.val("aaa");
let saisie = pseudo.val();
if(saisie.length < 5){
pseudo.css("border", "2px solid red");
}else{
pseudo.css("border", "2px solid green");
}
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
javascript | |
jquery |
Test name | Executions per second |
---|---|
javascript | 218479.6 Ops/sec |
jquery | 146263.4 Ops/sec |
I'd be happy to explain the benchmark and its options.
Benchmark Overview
The provided JSON represents a microbenchmarking test between two approaches: JavaScript Vanilla and jQuery. The test is designed to measure the performance of these two approaches when updating the value of an HTML input field's value attribute, applying a CSS style border conditionally based on the length of the new value.
Test Cases
There are two individual test cases:
pseudo
element using the document.querySelector()
and value
properties, then checks if the length of the new value is less than 5. If so, it sets a CSS border style to red; otherwise, it sets it to green.pseudo
element using the $()
function and the val()
method, then checks if the length of the new value is less than 5. If so, it sets a CSS border style to red; otherwise, it sets it to green.Library and Its Purpose
In the jQuery test case, the jQuery
library is used for its convenience functions like $()
, val()
, and css()
. These functions simplify DOM manipulation and styling operations, making it easier to write code that is both efficient and readable.
JavaScript Features/ Syntax
There are no special JavaScript features or syntax mentioned in this benchmark. Both test cases use standard JavaScript syntax and do not rely on any experimental or newly introduced features.
Options Compared
The two test cases compare the performance of JavaScript Vanilla and jQuery when:
Pros and Cons of Each Approach
Here are some pros and cons of each approach:
Other Alternatives
If you're looking for alternative libraries or approaches, here are a few options:
Benchmark Considerations
When interpreting benchmark results, consider the following factors:
I hope this explanation helps you understand the provided benchmarking test!