Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
find - filter js
(version: 0)
Comparing performance of:
array.find vs array.filter
Created:
4 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.29/angular.min.js"></script>
Script Preparation code:
var angularFilter = angular.injector(['ng']).get('$filter')('filter'); // Add array.where implementation Array.prototype.where = Array.prototype.where || function(predicate) { var results = [], len = this.length, i = 0; for (; i < len; i++) { var item = this[i]; if (predicate(item)) { results.push(item); } } return results; }; // Generate test array window.array = (function() { var arr = []; for (var i = 0; i < 100; ++i) { arr.push(i); } return arr; }()); grepAlone = function( elems, callback, invert ) { var callbackInverse, matches = [], i = 0, length = elems.length, callbackExpect = !invert; // Go through the array, only saving the items // that pass the validator function for ( ; i < length; i++ ) { callbackInverse = !callback( elems[ i ], i ); if ( callbackInverse !== callbackExpect ) { matches.push( elems[ i ] ); } } return matches; }; Array.prototype.find = function(predicate) { if (this == null) { throw new TypeError('Array.prototype.find called on null or undefined'); } if (typeof predicate !== 'function') { throw new TypeError('predicate must be a function'); } var list = Object(this); var length = list.length >>> 0; var thisArg = arguments[1]; var value; for (var i = 0; i < length; i++) { value = list[i]; if (predicate.call(thisArg, value, i, list)) { return value; } } return undefined; }; function getValue(el) { return el - 50 > 31; }
Tests:
array.find
array.find(getValue);
array.filter
array.filter(getValue);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
array.find
array.filter
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!
Related benchmarks:
JS Filter Test
JS Filter Test large array
JS Filter Test newer Lodash
JS Filter Test with fasterFilter
Comments
Confirm delete:
Do you really want to delete benchmark?