Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
ArrayFind
(version: 5)
Comparing performance of:
Test1 vs Test2 vs Test3 vs Test4 vs Test5 vs Test6 vs Test7
Created:
8 years ago
by:
Registered User
Jump to the latest result
Script Preparation code:
var arr = [ 'eThmP', '0braO', 'NlFtR', 'PX5Zp', 'BbD6m', 'VLdhh', 'jZnjN', 'UcWE3', 'BYNJ1', 'z3Oxy', 'AiAHj', 'ynkPJ', 'QaBNt', 'SnRZt', 'O56xK', 'qtWIK', 'UVgy6', 'UfTLi', 'FbjJM', 'KvznS', 'hOk9l', 'FUOc8', 'OBUtL', 'LkIIQ', 'dSfU4', 'zML1z', '2HGK0', '6NW1d', 'suA3T', 'aRagr', 'VLeHJ', 'bOjeW', 'VY5m4', 'T8TLT', 'mHoUd', 'YVh4v', 'aGY5z', 'p4iFm', 'OMPJd', 'xir0Q', 'ufSaN', 'iQkPe', 'ekZ0H', 'j9qqi', '4q9ht', 'jaKWO', '.', 'ypsgr', 'sE42b', 'NsEfX', 'khKiC' ]; var ar =[]; for (var i = 0; i < 100; i++) { ar = [ar, ...arr]; } Array.prototype.myio = function(search) { return (this.indexOf(search) !== -1); }; Array.prototype.myfora = function(search) { for (var i = 0; i < this.length; i++) { if(this[i][0] === search) return true; } return false; }; Array.prototype.myforb = function(search) { for (var i = 0; i < this.length; i++) { if(this[i][0] === search) { break; return true; } } return false; }; Array.prototype.myfe = function(search){ var tr = false; this.forEach(function(e){if(e === search)tr = true;}) return tr; }; Array.prototype.myaf = function(search) { return (typeof this.find(function(e){return e === search}) !== 'undefined'); };
Tests:
Test1
arr.myfora('BbD6m');
Test2
arr.myforb('AiAHj');
Test3
arr.myio('sE42b');
Test4
arr.myfe('sE42b');
Test5
arr.myaf('sE42b');
Test6
ar.myfe('sE42b');
Test7
ar.myaf('sE42b');
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (7)
Previous results
Fork
Test case name
Result
Test1
Test2
Test3
Test4
Test5
Test6
Test7
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 benchmark and explain what's being tested. **Benchmark Overview** The benchmark measures the execution time of various methods on an array in JavaScript. The test cases are designed to check how fast each method can find or iterate through the elements of the array. **Array Creation** Before running the tests, the script creates a large array `arr` containing 30 unique strings using a loop. **Custom Array Methods** The script defines four custom methods on the `Array.prototype`: 1. `myio(search)`: checks if an element is in the array 2. `myfora(search)`: finds the first occurrence of a value in the array 3. `myforb(search)`: finds the first occurrence of a value in the array using `break` and returns true as soon as found 4. `myfe(search)`: checks if any element is equal to the search value 5. `myaf(search)`: checks if a find() method returns a defined value **Test Cases** The test cases are small scripts that call one of these custom methods with a specific string as an argument. **Comparison** Here's what each test case is testing: 1. `Test5` ( `myaf(search)` ): checks if the find() method is fast. 2. `Test3` ( `myfe(search)` ): checks if the `myfe` method is slow. 3. `Test4` ( `myfora(search)` ): checks if the first occurrence method is fast. 4. `Test2` ( `myforb(search)` ): checks if the first occurrence method with break is slow. 5. `Test1` ( no specific method called, but close to the array's length ): checks if the test case doesn't fail due to out-of-bounds errors. **Browser and Device Results** The results show that: * Chromium 79 on Linux Desktop has varying execution times for each test case * The fastest test case is `Test5` (find() method), with an average of around 745,000 executions per second. * The slowest tests are `Test2` and `Test1`, with slower execution times. Overall, the benchmark suggests that: * Custom array methods can be faster than built-in methods like find() * The first occurrence method is generally faster than the others * Browser and device variations affect execution time Note: I've simplified some details for brevity. Let me know if you'd like more clarification!
Related benchmarks:
array test 123123123123
Array.from vs Array spread with mapping of values2
spread vs concat vs unshift Big string array
abcdfggg
Comments
Confirm delete:
Do you really want to delete benchmark?