Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash.filter vs Lodash.without
(version: 0)
Comparing performance of:
filter vs without
Created:
2 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Script Preparation code:
var arr = Array.from(Array(100000).keys())
Tests:
filter
_.filter(arr, o => o !== 999999);
without
_.without(arr, 999999);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
filter
without
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
2 years ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 YaBrowser/24.1.0.0 Safari/537.36
Browser/OS:
Yandex Browser 24 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
filter
1006.9 Ops/sec
without
1579.1 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and explain what is being tested. **Benchmark Definition** The provided JSON defines two microbenchmarks: `Lodash.filter` and `Lodash.without`. The benchmarks are comparing the performance of these two Lodash functions, which are part of a popular JavaScript utility library called Lodash. **What is Lodash?** Lodash is a comprehensive JavaScript library that provides a lot of useful functions for tasks such as data manipulation, object creation, string manipulation, and more. It was created by Jeremy Ashkenas in 2011 and has since become one of the most popular JavaScript libraries. The two benchmarked functions are: * `_.filter(arr, o => o !== 999999)`: This function takes an array (`arr`) as input and returns a new array containing only the elements that do not match the specified condition (`o !== 999999`). * `_.without(arr, 999999)`: This function takes an array (`arr`) as input and returns a new array containing all elements except those specified in the second argument (`999999`). **Options Compared** The benchmark is comparing two options: 1. Using Lodash's `filter` method. 2. Not using Lodash at all, i.e., implementing the logic from scratch. **Pros and Cons of Each Approach** * **Using Lodash's filter method:** + Pros: - Fast execution speed due to optimized implementation in JavaScript. - Low memory overhead since only a copy of the filtered array is created. - Easy to read and maintain, as the code is concise and follows the standard syntax. + Cons: - Adds an external dependency (Lodash library) that needs to be included in the project. - May have a larger binary size due to the inclusion of the Lodash library. * **Implementing the logic from scratch:** + Pros: - No external dependencies, which can reduce binary size and improve performance. - Can provide more control over the implementation and optimization. + Cons: - Requires manual implementation, which can be error-prone and time-consuming. - May not be as efficient as Lodash's optimized implementation. **Special Considerations** The benchmark is using a special JavaScript feature called "Arrow functions" (`. => o !== 999999`), which was introduced in ECMAScript 2015 (ES6). This allows for concise and readable code by eliminating the need to declare a function with `function() { ... }`. **Other Alternatives** If you want to implement the logic from scratch without using Lodash, you can use a simple loop or recursion to achieve the same result. Here is an example of how you could write it: ```javascript arr = arr.filter(x => x !== 999999); ``` Or, using recursion: ```javascript arr = []; for (var i = 0; i < arr.length; i++) { if (arr[i] !== 999999) { arr.push(arr[i]); } } ``` Note that these implementations may not be as efficient as Lodash's optimized implementation.
Related benchmarks:
Array.prototype.filter vs Lodash filter
Array.prototype.filter vs Lodash 4.17.5 filter
Array.prototype.filter vs Lodash filter bumped to million
Lodash.filter vs Lodash.without vs array.filter
Comments
Confirm delete:
Do you really want to delete benchmark?