Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash omit vs native vs babel-like approach
(version: 0)
Comparing performance of:
Lodash omit vs Object assign and delete vs Babel transpile vs Modified transpile using reduce vs Native using destructure
Created:
3 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src='https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js'></script>
Tests:
Lodash omit
const user = { name: 'Banana', phone: '1032012301d0s', address: 'Rua Banana'} const userWithoutPhone = _.omit(user, ["phone"]);
Object assign and delete
const user = { name: 'Banana', phone: '1032012301d0s', address: 'Rua Banana'} const userWithoutPhone = Object.assign({}, user); delete userWithoutPhone["phone"];
Babel transpile
const user = { name: 'Banana', phone: '1032012301d0s', address: 'Rua Banana'} // babel output function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } const userWithoutPhone = _objectWithoutProperties(user, ["phone"]);
Modified transpile using reduce
const user = { name: 'Banana', phone: '1032012301d0s', address: 'Rua Banana'} function objectWithoutKeys(obj, keys) { return Object.keys(obj).reduce((newObject, key) => { if (keys.indexOf(key) === -1) newObject[key] = obj[key]; return newObject; }, {}); } const userWithoutPhone = objectWithoutKeys(user, ["phone"]);
Native using destructure
const user = { name: 'Banana', phone: '1032012301d0s', address: 'Rua Banana'} const { address, ...userWithoutPhone } = user
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
Lodash omit
Object assign and delete
Babel transpile
Modified transpile using reduce
Native using destructure
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
**Benchmark Overview** The provided benchmark measures the performance of different approaches to remove a specific property from an object. The test cases compare the execution time of four methods: 1. Using Lodash's `omit` function 2. Using the native JavaScript `Object.assign` and `delete` methods 3. Using Babel-transpiled code with the `_objectWithoutProperties` function (similar to `Object.assign`, but without using `Object.keys`) 4. Using a modified transpile with a custom `reduce` method **Lodash Omit** The Lodash `omit` function is used in test case 1. This function creates a new object that excludes the specified properties. Pros: * Easy to use and well-documented * Widely supported and included in many JavaScript projects Cons: * Adds an extra dependency (Lodash) to the project * May not be as efficient as native methods, especially for large objects **Native Object.assign and delete** The native JavaScript `Object.assign` and `delete` methods are used in test case 2. This method creates a new object that includes all properties except those specified. Pros: * Fast and efficient, especially for small to medium-sized objects * Does not add any dependencies beyond the standard JavaScript library Cons: * Requires using both `Object.assign` and `delete`, which can be verbose * May require manual error handling if the property name is not found **Babel Transpile** The Babel-transpiled code uses the `_objectWithoutProperties` function (similar to `Object.assign`, but without using `Object.keys`). This method creates a new object that excludes the specified properties. Pros: * Transpiles to vanilla JavaScript, making it compatible with older browsers * Can be more readable and maintainable than native methods Cons: * Adds an extra dependency (Babel) to the project * May require additional configuration to ensure compatibility with all target browsers **Modified Transpile using reduce** The modified transpile uses a custom `reduce` method to create a new object that excludes the specified properties. This method is similar to the Babel-transpiled code, but implemented in JavaScript. Pros: * Customizable and can be optimized for specific use cases * Does not add any dependencies beyond standard JavaScript libraries Cons: * May require additional development effort to optimize performance and readability * Can be more complex and harder to maintain than native methods or the Babel-transpiled code **Device and Browser Variations** The benchmark results show variations in execution time across different devices (Desktop, Mobile) and browsers (Chrome 101). This highlights the importance of considering device and browser variations when optimizing performance. **Other Alternatives** If you're looking for alternative approaches, consider: * Using a library like `omit` from `lodash-omit` which provides similar functionality to Lodash's `omit`, but with less dependencies * Implementing a custom `reduce` method similar to the modified transpile code, but optimized for performance and readability * Using other JavaScript libraries or frameworks that provide built-in support for object manipulation and optimization Keep in mind that the best approach will depend on your specific use case, project requirements, and performance constraints.
Related benchmarks:
trim-loadsh vs native-trim
lodash omit vs spread omit using babel
lodash isEmpty vs native for empty strings
Lodash.js vs Native - empty
lodash omit vs spread omit modified
Comments
Confirm delete:
Do you really want to delete benchmark?