Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Remove undefined/null values from object - Lodash PickBy vs Native
(version: 0)
Comparing performance of:
Lodash vs Native
Created:
2 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.11/lodash.min.js"></script>
Script Preparation code:
var obj = { aaa: 'xxx', bbb: null, ccc: undefined, ddd: 12345, eee: true };
Tests:
Lodash
_.pickBy(obj, Boolean);
Native
function pickBy(obj) { return Object.fromEntries(Object.entries(obj).filter(([_, v]) => v != null)); } pickBy(obj);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Lodash
Native
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36
Browser/OS:
Chrome 125 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash
2632226.2 Ops/sec
Native
3816784.5 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**What is being tested?** The provided JSON benchmark tests two approaches to remove undefined/null values from an object: using Lodash's `pickBy` function and implementing it natively in JavaScript. **Options compared** There are two options being compared: 1. **Lodash's `pickBy` function**: This is a utility function from the popular JavaScript library Lodash. It takes an object and a predicate function as arguments, and returns a new object with only the key-value pairs for which the predicate function returns a truthy value. 2. **Native implementation of `pickBy`**: This is a custom implementation of the same logic, written in plain JavaScript. **Pros and Cons** **Lodash's `pickBy` function** Pros: * Faster execution: Lodash's implementation is optimized for performance and is likely to be faster than the native implementation. * Less boilerplate code: The user doesn't need to write their own code to implement this functionality. Cons: * Additional dependency: The benchmark requires the presence of the Lodash library, which may not be desirable in all scenarios. * Licensing restrictions: Depending on the version of Lodash used, there may be licensing restrictions or limitations on how it can be used. **Native implementation** Pros: * No dependencies: This approach doesn't require any external libraries, making it more suitable for environments where Lodash is not available. * Total control: The user has full control over the implementation and can optimize it further if needed. Cons: * More code: The native implementation requires writing more code to achieve the same result as Lodash's `pickBy` function. * Potential performance differences: Depending on the implementation, the native version might not be faster than the Lodash version. **Library: Lodash** Lodash is a popular JavaScript utility library that provides a wide range of functions for tasks such as array manipulation, object transformation, and more. The `pickBy` function is one of its many useful utilities for working with objects. **Special JS feature or syntax** This benchmark does not use any special JavaScript features or syntax beyond the standard language specification. However, it's worth noting that some versions of Lodash may support certain advanced features like async/await, but these are not used in this specific implementation. **Other alternatives** If you wanted to implement a similar solution without using Lodash, you could consider other libraries or frameworks that provide object manipulation utilities, such as: * Moment.js (for date-related tasks) * Immutable.js (for immutable data structures and transformations) * Ramda (a smaller, more lightweight alternative to Lodash) Alternatively, you could choose to implement the logic yourself, without relying on any external libraries.
Related benchmarks:
lodash.values vs Object.values
Native Undefined vs Lodash isUndefined
Native Object.values().some() vs lodash _.some()
Comparing performance of native .length and Lodash _.isEmpty v2
JS Native vs Loadash
Comments
Confirm delete:
Do you really want to delete benchmark?