Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Plain js vs OmitBy
(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 isNull = a => !Boolean(a) const omitBy = (obj, check) => { obj = { ...obj } Object.entries(obj).forEach(([key, value]) => check(value) && delete obj[key]) return obj } omitBy(basePalette, isNull)
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 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36
Browser/OS:
Chrome 123 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Plain Js
836439.1 Ops/sec
LoDash OmitBy
1443849.4 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the benchmark and its components. **Benchmark Overview** The benchmark compares the performance of two approaches to remove null or undefined values from an object: Plain JavaScript (without using LoDash) versus LoDash's `omitBy` function. **Plain JavaScript Approach** The Plain JavaScript approach uses a simple iterative method to delete properties with null or undefined values. The code is as follows: ```javascript const isNull = a => !Boolean(a) const omitBy = (obj, check) => { obj = { ...obj } Object.entries(obj).forEach(([key, value]) => check(value) && delete obj[key]) return obj } ``` **LoDash `omitBy` Function** The LoDash `omitBy` function is a utility function that takes an object and a check function as arguments. The check function determines which properties to remove from the object. In this benchmark, the LoDash `isNullable` function is used as the check function. ```javascript _.omitBy(basePalette, _.isNullable) ``` **Library: LoDash** LoDash is a popular JavaScript utility library that provides various functions for tasks like data manipulation, string manipulation, and more. The `omitBy` function is one of its utility functions, designed to remove properties from an object based on a provided check function. **Special JS Feature/Syntax: None mentioned in this benchmark** No special JavaScript features or syntax are used in this benchmark. **Other Alternatives** If you're looking for alternatives to LoDash's `omitBy` function or want to implement a similar functionality without using an external library, you can use the Plain JavaScript approach or other libraries like Lodash Lite (which includes some of its utility functions), Moment.js (for date manipulation and string formatting), or even vanilla JavaScript with some custom code. Keep in mind that while implementing from scratch might be interesting for learning purposes, using existing libraries like LoDash or Lodash Lite can save time and provide a more comprehensive set of utilities.
Related benchmarks:
lodash.head() vs [0] updated with optional chaining
Lodash.js vs Native - empty
lodash omit vs spread omit modified
Lodash isEmpty vs Native Javascript
lodash noop vs new function vs optional chaining
Comments
Confirm delete:
Do you really want to delete benchmark?