Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
lodash omit vs spread omit vs spread omit using babel
(version: 0)
Comparing performance of:
lodash omit vs spread omit vs spread as compiled by babel
Created:
6 years 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>
Tests:
lodash omit
const a = { aa: 'oh', bb: 'my' }; const b = _.omit(a, 'aa');
spread omit
const a = { aa: 'oh', bb: 'my' }; const { aa, ...b } = a;
spread as compiled by babel
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } var a = { aa: 'oh', bb: 'my' }; var aa = a.aa, b = _objectWithoutProperties(a, ["aa"]);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (3)
Previous results
Fork
Test case name
Result
lodash omit
spread omit
spread as compiled by babel
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/135.0.0.0 Safari/537.36
Browser/OS:
Chrome 135 on Mac OS X 10.15.7
View result in a separate tab
Embed
Embed Benchmark Result
Test name
Executions per second
lodash omit
3114972.5 Ops/sec
spread omit
31939096.0 Ops/sec
spread as compiled by babel
18025558.0 Ops/sec
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll break down the benchmark and explain what's being tested, compared, and the pros and cons of each approach. **Benchmark Definition** The benchmark is comparing three ways to remove specific properties from an object: 1. Using Lodash `omit` function 2. Using the spread operator (`...`) with destructuring 3. Compiling the second approach using Babel **Library: Lodash** Lodash is a popular JavaScript utility library that provides a wide range of functions for working with arrays, objects, and more. The `omit` function is used to remove specific properties from an object. **Test Cases** There are three test cases: 1. **Lodash `omit`**: This test case uses the Lodash `omit` function to remove the `'aa'` property from an object `{ aa: 'oh', bb: 'my' }`. The expected result is a new object `{ bb: 'my' }`. 2. **Spread operator with destructuring**: This test case uses the spread operator (`...`) with destructuring to create a new object that includes all properties except `'aa'`. The syntax is `const { aa, ...b } = a;`, where `a` is the original object. 3. **Compiled spread operator using Babel**: This test case compiles the second approach (spread operator with destructuring) using Babel to generate JavaScript that can be executed by older browsers. **Comparison** The benchmark compares the performance of each approach: 1. Lodash `omit`: This is a built-in function in Lodash, so it's likely to be optimized for performance. 2. Spread operator with destructuring: This approach is more concise and easier to read than using an explicit `omit` function, but it may incur a slight performance penalty due to the creation of a new object. 3. Compiled spread operator using Babel: This approach allows older browsers to execute modern JavaScript code, which can be slower than optimized built-in functions like Lodash `omit`. **Pros and Cons** 1. **Lodash `omit`**: * Pros: Fast, efficient, and well-optimized. * Cons: Requires an external library (Lodash). 2. **Spread operator with destructuring**: * Pros: Concise, readable, and easy to understand. * Cons: May incur a slight performance penalty due to object creation. 3. **Compiled spread operator using Babel**: * Pros: Allows older browsers to execute modern JavaScript code. * Cons: Generates slower JavaScript code than optimized built-in functions. **Other Alternatives** If you don't want to use Lodash, you could consider alternative approaches: 1. Using the `Object.keys()` and `reduce()` methods to create a new object without specific properties. 2. Using a library like `omit` from another utility library (e.g., Underscore.js). 3. Implementing your own custom implementation for removing specific properties from an object. Keep in mind that these alternatives may have varying performance characteristics, so it's essential to test and optimize them according to your specific use case.
Related benchmarks:
lodash omit vs. spread omit
lodash omit versus spread omit
lodash omit vs spread omit using babel
lodash omit vs spread omit modified
Comments
Confirm delete:
Do you really want to delete benchmark?