Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash omit vs vanilla using Object.fromEntries
(version: 0)
Comparing performance of:
Lodash omit vs Object.fromEntries
Created:
4 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 black = 'black' var green = 'green' var orange = 'orange' var red = 'red' var darkRed = 'darkRed' var blue = 'blue' var lightBlue = 'lightBlue' var navy = 'navy' var basePalette = { black, green, orange, red, darkRed, blue, lightBlue, navy }
Tests:
Lodash omit
_.omit(basePalette, ['orange','red', 'darkRed'])
Object.fromEntries
function exclude(original, ...keysToOmit) { const newEntries = Object.entries(original).filter(([key]) => !keysToOmit.includes(key)) return Object.fromEntries(newEntries) } exclude(basePalette, 'orange', 'red', 'darkRed')
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Lodash omit
Object.fromEntries
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/130.0.0.0 Safari/537.36 Edg/130.0.0.0
Browser/OS:
Chrome 130 on Windows
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
Lodash omit
666423.1 Ops/sec
Object.fromEntries
1262035.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the JavaScript microbenchmark, MeasureThat.net. **Benchmark Overview** The benchmark compares two approaches to remove certain keys from an object: `_.omit` from Lodash and using `Object.fromEntries`. The goal is to determine which approach is faster in removing specific keys from a predefined color palette. **Options Compared** 1. **Lodash `_.omit`**: This function takes an object as its first argument and one or more keys to exclude as arguments. It returns a new object that contains all the key-value pairs from the original object, except for the specified keys. 2. **Vanilla `Object.fromEntries` with filtering**: This approach uses the `Object.entries()` method to convert the object into an array of [key, value] pairs. Then, it filters out the desired keys using the `filter()` method and finally converts the resulting array back into an object using `Object.fromEntries()`. The new object is returned without any specific key removal. **Pros and Cons** 1. **Lodash `_.omit`**: * Pros: A well-tested, efficient function that handles more cases than vanilla implementation (e.g., handling nested objects). * Cons: Adds dependency on Lodash library. 2. **Vanilla `Object.fromEntries` with filtering**: * Pros: Lightweight, no additional dependencies required, and flexible for more complex key removal scenarios. * Cons: Requires extra steps to convert between object and array formats. **Library: Lodash** Lodash is a popular JavaScript utility library that provides various functions for tasks like array manipulation, object transformation, and more. In this benchmark, `_.omit` is used to remove specific keys from an object. **Special JS Feature/Syntax (not applicable)** This benchmark does not use any special JavaScript features or syntax that would affect its execution. **Other Alternatives** If you're interested in exploring alternative approaches for removing keys from objects, some options include: 1. **Using `Object.assign()` and spreading**: You can create a new object by spreading the original object's entries, excluding the desired keys. 2. **Using `Map` instead of `Object`**: If your use case allows it, using a `Map` to store key-value pairs might provide better performance for removing keys. Here's an example implementation: ```javascript const originalMap = new Map(Object.entries(basePalette)); originalMap.delete('orange'); originalMap.delete('red'); originalMap.delete('darkRed'); const result = Object.fromEntries(originalMap); ``` Keep in mind that the best approach depends on your specific use case, performance requirements, and personal preference.
Related benchmarks:
Lodash omit vs Native object destruction
isEmpty vs Object.keys
Lodash IsEmpty for objects
Comparing performance of native .length and Lodash _.isEmpty v2
lodash noop vs new function vs optional chaining
Comments
Confirm delete:
Do you really want to delete benchmark?