Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Plain js vs OmitBy(3)
(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', blackOne: undefined, blackTwo: undefined, blackThree: undefined, blackFour: undefined, blackFive: undefined, blackSix: undefined, blackSeven: undefined, }
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
const isNullable = (v) => v == undefined || v == null || (Array.isArray(v) && v.length < 1) _.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:
2 years ago
)
User agent:
Mozilla/5.0 (iPhone; CPU iPhone OS 17_1_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.1.2 Mobile/15E148 Safari/604.1
Browser/OS:
Mobile Safari 17 on iOS 17.1.2
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Plain Js
738836.7 Ops/sec
LoDash OmitBy
642713.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll explain what's being tested in the provided JSON, describe the options being compared, and discuss their pros and cons. **What's being tested:** MeasureThat.net is testing the performance of two approaches to remove null or undefined values from an object: 1. **Plain JavaScript**: This approach uses a custom function `isNullable` to check if a value is null, undefined, or has an empty array. 2. **LoDash OmitBy**: This approach uses the LoDash library's `omitBy` function to achieve the same result. **Options being compared:** The two options being tested are: * Plain JavaScript (using a custom function) * LoDash OmitBy (using the LoDash library) **Pros and Cons of each approach:** 1. **Plain JavaScript**: * Pros: + No external dependencies required + Easy to understand and implement for developers familiar with JavaScript * Cons: + May be slower due to the overhead of function calls and custom logic + Requires more code to implement the `isNullable` function 2. **LoDash OmitBy**: * Pros: + Faster execution speed (thanks to optimized native code) + Less code required to achieve the same result * Cons: + External dependency on LoDash library, which may not be suitable for all projects + May require additional setup or configuration **Library: LoDash** LoDash is a popular JavaScript utility library that provides a collection of functional programming functions, including `omitBy`, which removes null or undefined values from an object. The library is widely used in the industry and offers performance benefits. **Special JS feature/syntax: None mentioned** There are no special JavaScript features or syntax being tested in this benchmark. **Other alternatives:** If you're interested in alternative approaches to remove null or undefined values from an object, some other options include: * Using `Array.prototype.filter()` method to create a new array with only the non-null/undefined values * Utilizing modern JavaScript features like optional chaining (`?.`) and the nullish coalescing operator (`??`) * Leveraging libraries like Lodash (as shown in this benchmark) or other utility libraries that provide similar functionality. These alternatives may offer trade-offs in terms of performance, code complexity, or external dependencies.
Related benchmarks:
Native Undefined vs Lodash isUndefined
lodash omit vs spread omit modified
lodash isNil vs === null || === undefined
lodash noop vs new function
lodash noop vs new function vs optional chaining
Comments
Confirm delete:
Do you really want to delete benchmark?