Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash omitBy vs Array.reduce omit by 100k
(version: 0)
Comparing performance of:
Lodash vs Native vs Native with Entries
Created:
one year 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 max2 = 100000; var data = {}; for (var i = 0; i <= max2; i++) { data['id'] = i; }
Tests:
Lodash
_.omitBy(data, (item) => item.id === 5000)
Native
Object.keys(data).reduce((result, key) => { if (key !== 5000) { result[key] = data[key]; } return result; }, {})
Native with Entries
Object.entries(data).reduce((result, entry) => { if (entry[1] !== 5000) { result[entry[0]] = entry[1]; } return result; }, {})
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
Lodash
Native
Native with Entries
Fastest:
N/A
Slowest:
N/A
Latest run results:
Run details:
(Test run date:
one year ago
)
User agent:
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36
Browser/OS:
Chrome 136 on Linux
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash
2930443.2 Ops/sec
Native
40675576.0 Ops/sec
Native with Entries
32789788.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll explain the benchmark in detail. **Benchmark Overview** The benchmark compares the performance of three approaches: Lodash's `omitBy` function and two native JavaScript methods, `Array.prototype.reduce()` with an if- condition and `Object.entries().reduce()`. The goal is to remove a specific property (`id`) from all objects in the `data` array. **Options Compared** 1. **Lodash's `omitBy`**: Lodash is a utility library that provides various functions for tasks like filtering, mapping, and reducing data. `omitBy` removes properties from objects based on a condition. 2. **Native `Array.prototype.reduce()` with an if- condition**: This method uses the reduce function to iterate over the array, creating a new object that includes only the desired properties. 3. **Native `Object.entries().reduce()`**: Similar to the previous approach, but uses the entries() method to get an array of key-value pairs in the object. **Pros and Cons** 1. **Lodash's `omitBy`**: * Pros: concise code, easy to read, and maintainable. * Cons: adds overhead due to the library, might not be optimized for performance. 2. **Native `Array.prototype.reduce()` with an if- condition**: * Pros: can be more efficient since it doesn't involve a library or additional function calls. * Cons: code might be less readable and maintainable due to the nested if statement. 3. **Native `Object.entries().reduce()`**: * Pros: concise code, easy to read, and maintainable. * Cons: might have slightly higher overhead than the native reduce() method due to the additional function call. **Library Used** The benchmark uses Lodash (version 4.17.5) for its `omitBy` function. Lodash is a popular utility library that provides various functions for tasks like filtering, mapping, and reducing data. **Special JS Feature/Syntax** None mentioned in this benchmark. The code only uses standard JavaScript features and syntax. **Other Alternatives** Alternative approaches to remove properties from objects could include: * Using `Object.assign()` with an empty object to create a new object without the desired property. * Utilizing a library like Underscore.js, which provides similar functionality to Lodash's `omitBy` function. * Implementing a custom loop or recursive function to achieve the same result. **Benchmark Preparation Code** The script preparation code creates a large dataset `data` with 100,000 objects, each containing an `id` property. This is done to simulate a realistic use case for removing properties from a large array of objects. The HTML preparation code includes the Lodash library (version 4.17.5) in the `<script>` tag to enable the benchmark's tests that rely on this function.
Related benchmarks:
lodash groupBy vs Array.reduce (2)
lodas2 groupBy vs Array.reduce
lodash groupBy vs Array.reduce on million items
lodash groupBy vs Array.reduce 100k corrected
lodash groupBy vs Array.reduce 100k with array push
Comments
Confirm delete:
Do you really want to delete benchmark?