Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
ul li each test2
(version: 0)
Comparing performance of:
jQuery vs jQuery 2
Created:
6 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <ul class="food-list"> <li>北海道</li> <li>青森県</li> <li>岩手県</li> <li>宮城県</li> <li>秋田県</li> <li>山形県</li> <li>福島県</li> <li>茨城県</li> <li>栃木県</li> <li>群馬県</li> <li>埼玉県</li> <li>千葉県</li> <li>東京都</li> <li>神奈川県</li> <li>新潟県</li> <li>富山県</li> <li>石川県</li> <li>福井県</li> <li>山梨県</li> <li>長野県</li> <li>岐阜県</li> <li>静岡県</li> <li>愛知県</li> <li>三重県</li> <li>滋賀県</li> <li>京都府</li> <li>大阪府</li> <li>兵庫県</li> <li>奈良県</li> <li>和歌山県</li> <li>鳥取県</li> <li>島根県</li> <li>岡山県</li> <li>広島県</li> <li>山口県</li> <li>徳島県</li> <li>香川県</li> <li>愛媛県</li> <li>高知県</li> <li>福岡県</li> <li>佐賀県</li> <li>長崎県</li> <li>熊本県</li> <li>大分県</li> <li>宮崎県</li> <li>鹿児島県</li> <li>沖縄県</li> </ul>
Tests:
jQuery
var el = document.querySelectorAll('.food-list li'); var targetText; var searchText = "熊本" for(var i=0; i<el.length; i++) { targetText = el[i].textContent; //ここもjquery使わない形にする。 // 検索対象となるリストに入力された文字列が存在するかどうかを判断 if (searchText !== "" && targetText.indexOf(searchText) != -1) { el[i].classList.remove("hidden"); } else { el[i].classList.add("hidden"); } }
jQuery 2
var el = document.querySelectorAll('.food-list li'); var targetText; var searchText = "熊本" for(var i=0; i<el.length; i++) { targetText = el[i].textContent; //ここもjquery使わない形にする。 // 検索対象となるリストに入力された文字列が存在するかどうかを判断 if (searchText !== "" && targetText.indexOf(searchText) != -1) { if (el[i].classList.contains('hidden')) { el[i].classList.remove("hidden"); } } else { if (!el[i].classList.contains('hidden')) { el[i].classList.add("hidden"); } } }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
jQuery
jQuery 2
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark definition and test cases. **Overview** The goal of this benchmark is to measure the performance of two different approaches for hiding elements in an HTML list based on a search query. The benchmark uses jQuery, a popular JavaScript library, to achieve this functionality. **Benchmark Definition** The benchmark definition consists of three parts: 1. **Script Preparation Code**: This code is executed once before running the test case. It includes a script tag that loads the jQuery library. 2. **Html Preparation Code**: This code is executed once before running each individual test case. It includes an HTML structure with a list (`<ul>`) containing items (`<li>`) and a script that sets up the test environment. 3. **Benchmark Definition**: This code defines the test logic, which involves using jQuery to hide or show elements in the list based on a search query. **Individual Test Cases** There are two individual test cases: 1. **jQuery**: This test case uses jQuery's `document.querySelectorAll()` method to select all elements with class `food-list li`. It then loops through each element and checks if the text content matches the search query (`"熊本"`). If a match is found, the element's class is removed from the `hidden` set. Otherwise, the element's class is added. 2. **jQuery 2**: This test case is similar to the first one, but it uses jQuery's `el[i].classList.contains()` method instead of `el[i].classList.remove()`. This approach might be slightly more efficient, as it avoids removing a class and then checking if it's present. **Library** The library used in both test cases is jQuery. It provides various methods for manipulating the DOM, such as `document.querySelectorAll()` and `classList.contains()`. **Special JS Feature/Syntax** There are no special JavaScript features or syntax used in this benchmark. However, it's worth noting that using jQuery can introduce some overhead due to its asynchronous nature and the need to handle different browser versions. **Pros and Cons of Different Approaches** 1. **jQuery**: Pros: * Widely supported and well-maintained. * Easy to use and understand. Cons: * Can introduce overhead due to its asynchronous nature and multiple browser support. 2. **jQuery 2**: Pros: * Might be slightly more efficient than jQuery, as it avoids removing a class and then checking if it's present. Cons: * Requires explicit class management (adding and removing classes). 3. **Native JavaScript Approach**: This approach would involve using the `document.querySelectorAll()` method and iterating through each element to check for matches. While this might be more efficient than using jQuery, it requires more manual work and is less convenient. **Other Alternatives** If you're looking for alternatives to jQuery, some popular options include: 1. **Vanilla JavaScript**: Using native JavaScript methods and properties to achieve similar functionality. 2. **Lodash**: A utility library that provides functions for common tasks, including DOM manipulation. 3. **Preact**: A lightweight alternative to React, which can be used for DOM manipulation and other tasks. In summary, the benchmark is designed to measure the performance of two different approaches for hiding elements in an HTML list based on a search query using jQuery. The pros and cons of each approach are discussed, along with some alternatives to jQuery.
Related benchmarks:
jQuery.text() vs Element.textContent
ul li each test
Vanilla JS VS Jquery | rem
jQuery.text() vs Element.textContent (jQuery 1.11.3
Comments
Confirm delete:
Do you really want to delete benchmark?