Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Plain js vs OmitBy(2)
(version: 0)
Testing LoDash's omitBy agains plain js
Comparing performance of:
Plain Js vs LoDash OmitBy
Created:
3 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.js"></script>
Script Preparation code:
var basePalette = { black: undefined, green: null, orange: 'orange', red: null, darkRed: 'darkRed', blue: 'blue', lightBlue: 'lightBlue', navy: 'navy' }
Tests:
Plain Js
const isNullable = (obj) => obj === undefined || obj === null || (Array.isArray(obj) && obj.length < 1) const skipNullable = (obj) => { const temp = {} Object.keys(obj).forEach((key) => { if (isNullable(obj[key])) return temp[key] = obj[key] }) return temp } skipNullable(basePalette)
LoDash OmitBy
_.omitBy(basePalette, _.isNullable )
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Plain Js
LoDash OmitBy
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36
Browser/OS:
Chrome 129 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Plain Js
507476.6 Ops/sec
LoDash OmitBy
905006.8 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down what's being tested in this benchmark. **Overview** The benchmark is comparing the performance of two approaches to remove null and undefined values from an object: plain JavaScript and LoDash's `omitBy` function. **Plain JavaScript vs OmitBy(2)** OmitBy(2) is a utility function provided by LoDash, a popular JavaScript utility library. The number 2 in the function name indicates that it will skip removing null or undefined values up to the second level of nested objects. Let's analyze the two approaches: **Plain JavaScript** The plain JavaScript approach uses two separate functions: `isNullable` and `skipNullable`. The `isNullable` function checks if an object is null, undefined, or has a length of 0 (in the case of arrays). The `skipNullable` function iterates through the keys of the input object and skips any key whose value is nullable. If all values are non-nullable, it returns the original object. **Pros of Plain JavaScript** * Simple and easy to understand * Can be easily modified or extended if needed **Cons of Plain JavaScript** * May be slower due to the iterative approach * Requires more code than LoDash's `omitBy` **LoDash OmitBy** The `omitBy` function from LoDash takes an object and a function that determines which values should be removed. In this case, it uses `_.isNullable` to check if a value is null or undefined. **Pros of LoDash OmitBy** * Fast and efficient * Provides a simple and elegant way to remove nullable values **Cons of LoDash OmitBy** * Requires the LoDash library to be included in the test environment * May have overhead due to external dependencies **Library: Lodash** Lodash is a popular JavaScript utility library that provides various functions for tasks such as array manipulation, object transformation, and functional programming. The `omitBy` function is part of Lodash's core functionality. The latest benchmark results show that LoDash OmitBy outperforms the plain JavaScript approach, with an execution rate of 1.79x higher than Plain Js on this test case. **Other Alternatives** If you don't want to use a third-party library like LoDash, you can consider using other alternatives for removing nullable values from objects: * Using `Object.keys()` and `forEach()` to iterate through the keys of the object * Utilizing the `Array.prototype.filter()` method to remove nullable values * Leveraging modern JavaScript features like `Optional Chaining` (e.g., `?.`) or `nullish Coalescing` (`??`) to simplify the removal process Keep in mind that each alternative has its pros and cons, and some may be more suitable depending on your specific use case.
Related benchmarks:
lodash.head() vs [0] updated with optional chaining
lodash omit vs spread omit modified
lodash isNil vs native isNil with if
lodash noop vs new function
lodash noop vs new function vs optional chaining
Comments
Confirm delete:
Do you really want to delete benchmark?