Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
text compare array, indexof and function(some, array)3
(version: 2)
Comparing performance of:
if indexof vs function some array vs if includes
Created:
2 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
containerTXTfilt = "Hunter made a surprise appearance on Capitol Hill Wednesday as Republicans work to hold him in contempt of Congress. The House Oversight and Judiciary Committee will vote Wednesday on a contempt resolution that could aid Republicans in pushing to impeach President Joe Biden.If the resolution passes, it will go to the House for a vote before being handed over to the Department of Justice to prosecute.READ MORE | House Republicans probing whether Biden was involved in sons subpoena defiance: Impeachable offenseThe presidents son intentionally defied a congressional subpoena in December, instead giving a press conference in which he decried those investigating President Bidens alleged connection to his business deals.For six years, I have been the target of the unrelenting Trump attack machine shouting Wheres Hunter Well, here is my answer, I am here, he told reporters.Comment bubbleJOIN THE CONVERSATION" textArray = ["자댕이", "보댕이", "좃물", "보짓물", "좆뱀", "실잦", "자적자", "실좆", "갈좆", "좆빨", "보적보", "걸레", "보징어", "보릉", "갈보", "보빨", "허벌", "흉자", "소추", "자들자들", "피싸", "6.9"]; isTextContained = textArray.some(function (text) { return containerTXTfilt.includes(text); });
Tests:
if indexof
if (~containerTXTfilt.indexOf('자댕이') || ~containerTXTfilt.indexOf('보댕이') || ~containerTXTfilt.indexOf('좃물') || ~containerTXTfilt.indexOf('보짓물') || ~containerTXTfilt.indexOf('좆뱀') || ~containerTXTfilt.indexOf('실잦') || ~containerTXTfilt.indexOf('자적자') || ~containerTXTfilt.indexOf('실좆') || ~containerTXTfilt.indexOf('갈좆') || ~containerTXTfilt.indexOf('좆빨') || ~containerTXTfilt.indexOf('보적보') || ~containerTXTfilt.indexOf('걸레') || ~containerTXTfilt.indexOf('보징어') || ~containerTXTfilt.indexOf('보릉') || ~containerTXTfilt.indexOf('갈보') || ~containerTXTfilt.indexOf('보빨') || ~containerTXTfilt.indexOf('허벌') || ~containerTXTfilt.indexOf('흉자') || ~containerTXTfilt.indexOf('소추') || ~containerTXTfilt.indexOf('자들자들') || ~containerTXTfilt.indexOf('피싸') || ~containerTXTfilt.indexOf('6.9')) { console.log('확인'); }
function some array
if (isTextContained) { console.log("명령 실행");}
if includes
if (containerTXTfilt.includes('자댕이') || containerTXTfilt.includes('보댕이') || containerTXTfilt.includes('좃물') || containerTXTfilt.includes('보짓물') || containerTXTfilt.includes('좆뱀') || containerTXTfilt.includes('실잦') || containerTXTfilt.includes('자적자') || containerTXTfilt.includes('실좆') || containerTXTfilt.includes('갈좆') || containerTXTfilt.includes('좆빨') || containerTXTfilt.includes('보적보') || containerTXTfilt.includes('걸레') || containerTXTfilt.includes('보징어') || containerTXTfilt.includes('보릉') || containerTXTfilt.includes('갈보') || containerTXTfilt.includes('보빨') || containerTXTfilt.includes('허벌') || containerTXTfilt.includes('흉자') || containerTXTfilt.includes('소추') || containerTXTfilt.includes('자들자들') || containerTXTfilt.includes('피싸') || containerTXTfilt.includes('6.9')) { console.log('확인'); }
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
if indexof
function some array
if includes
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Browser/OS:
Chrome 120 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
if indexof
562577.9 Ops/sec
function some array
12717188.0 Ops/sec
if includes
563508.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided JSON benchmark and explain what is being tested. **Benchmark Definition** The benchmark definition is a JavaScript function that takes two inputs: 1. `containerTXTfilt`: a string containing various text values 2. A conditional statement (either `if`, `function some array`, or `includes`) that checks if a specific substring exists within the `containerTXTfilt` string. **Options Compared** The benchmark compares three different approaches: 1. **`if indexof`**: uses the `indexOf()` method to check for the existence of a substring. 2. **`function some array`**: defines an anonymous function (using `some()`) that iterates through the `containerTXTfilt` string to check if any of the specified substrings exist. 3. **`if includes`**: uses the `includes()` method to check for the existence of a substring. **Pros and Cons** * **`if indexof`**: This approach is likely to be the fastest, as it leverages the optimized implementation of the `indexOf()` method in JavaScript engines. However, it may not work correctly if the input string contains Unicode characters or non-ASCII characters. * **`function some array`**: This approach requires iterating through the entire string, which can be slower than using `indexOf()`. However, it is more flexible and works with any character set, including Unicode. * **`if includes`**: This approach is similar to `if indexof`, but uses a different method name. It may have slightly better performance in some cases. **Library Usage** None of the benchmark options use external libraries. **Special JS Features or Syntax** The `some()` function used in the `function some array` option is a built-in JavaScript feature, introduced in ECMAScript 2015 (ES6). It allows iterating through an array-like object and stopping execution as soon as a predicate (in this case, a boolean condition) returns true. **Other Alternatives** If none of these options were available, alternative approaches could include: * Using regular expressions to search for the substrings * Implementing a custom loop-based solution using `for` loops or other iteration constructs However, it's worth noting that the performance differences between these approaches are likely to be small, and the choice of approach may depend on specific requirements or use cases.
Related benchmarks:
Map vs Property Accessor
[MH-4355]: lodash / es6 filter perf
find the boss
IndexOf vs Includes in string - larger string edition
Comments
Confirm delete:
Do you really want to delete benchmark?