Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
.includes vs mass compare vs lookup vs integrated array
(version: 0)
Comparing performance of:
mass compare vs array test vs lookup table vs integrated array
Created:
4 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
function activeElementIsImportant1() { let activeElement = "someString"; if (activeElement == 'someString11' || activeElement == '123' || activeElement == 'qeqw' || activeElement == 'qwewqdadas' || activeElement == 'someString1' || activeElement == 'someString12' || activeElement == 'asdqwwqd' || activeElement == 'asdadqw' || activeElement == 'xzczxaq' || activeElement == 'zxczx' || activeElement == '12321' || activeElement == 'qwewq' || activeElement == 'asdasdasdsa' || activeElement == 'czxcz' || activeElement == 'vbvbvb' || activeElement == 'wwww' || activeElement == '121' || activeElement == '12321312' || activeElement == 'zxzxzxzxzxzx' || activeElement == '3333') { return true; } else { return false; }; }; const compareArray = ['someString11', '123', 'qeqw', 'qwewqdadas', 'someString1', 'someString12', 'asdqwwqd', 'asdadqw', 'xzczxaq', 'zxczx', '12321', 'qwewq', 'asdasdasdsa', 'czxcz', 'vbvbvb', 'wwww', '121', '12321312', 'zxzxzxzxzxzx', '3333']; function activeElementIsImportant2() { if (compareArray.includes("someString")) { return true; } else { return false; }; }; const lookup = new Map([ ['someString11'], ['123'], ['qeqw'], ['qwewqdadas'], ['someString1'], ['someString12'], ['asdqwwqd'], ['asdadqw'], ['xzczxaq'], ['zxczx'], ['12321'], ['qwewq'], ['asdasdasdsa'], ['czxcz'], ['vbvbvb'], ['wwww'], ['121'], ['12321312'], ['zxzxzxzxzxzx'], ['3333'] ]); function activeElementIsImportant3() { if (lookup.has("someString")) { return true; } else { return false; }; }; //ignore the indentation function activeElementIsImportant4() { if (['someString11', '123', 'qeqw', 'qwewqdadas', 'someString1', 'someString12', 'asdqwwqd', 'asdadqw', 'xzczxaq', 'zxczx', '12321', 'qwewq', 'asdasdasdsa', 'czxcz', 'vbvbvb', 'wwww', '121', '12321312', 'zxzxzxzxzxzx', '3333'].includes("someString")) { return true; } else { return false; }; };
Tests:
mass compare
let k = activeElementIsImportant1();
array test
let k = activeElementIsImportant2();
lookup table
let k = activeElementIsImportant3();
integrated array
let k = activeElementIsImportant4();
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
mass compare
array test
lookup table
integrated array
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 dive into the explanation of the provided benchmark. **Benchmark Overview** The benchmark compares the performance of four different approaches to check if a string exists in an array or lookup table: 1. `mass compare` (also known as a linear search) 2. `array test` 3. `lookup table` 4. `integrated array` **Options Compared** * **Mass Compare**: Uses a simple loop to iterate through the array and checks if the target string is present. * **Array Test**: Directly uses the `includes()` method on the array, which performs a linear search. * **Lookup Table**: Creates a Map object with the strings as keys and then uses the `has()` method to check if the target string exists in the map. * **Integrated Array**: Treats the array as an integrated data structure where every element has a reference to every other element. This approach is not a common technique, but it's mentioned in the benchmark definition. **Pros and Cons of Each Approach** 1. **Mass Compare**: * Pros: Simple to implement and understand. * Cons: Has a high time complexity (O(n)) and may be slow for large arrays. 2. **Array Test**: Also has a linear search time complexity (O(n)), but it's implemented using the `includes()` method, which is more efficient than a simple loop. 3. **Lookup Table**: * Pros: Has a fast lookups (O(1)) on average, making it suitable for large arrays or datasets. * Cons: Requires extra memory to store the lookup table and key-value pairs. 4. **Integrated Array**: This approach is not recommended due to its complexity and potential performance issues. **Benchmark Results** The latest benchmark results show that: * `array test` (using `includes()`) performs best with 132,966,554 executions per second on a desktop Chrome 102 browser. * `lookup table` comes in second with 132,945,511 executions per second. * `mass compare` takes the third spot with 132,264,950 executions per second. * `integrated array` performs poorly with 130,502,850 executions per second. In summary, the results suggest that using an `array test` approach with the `includes()` method provides the best performance, followed closely by a `lookup table` implementation. The `mass compare` approach is slower but still suitable for small to medium-sized arrays. The `integrated array` approach is not recommended due to its complexity and potential performance issues.
Related benchmarks:
Array.Includes vs a few strict equals
two condition if vs includes compare
chain of or equals vs includes vs equal to many things
IF vs Array.includes()
equals vs includes (one value)
Comments
Confirm delete:
Do you really want to delete benchmark?