Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Lodash omit vs es omit vs compiled omit vs rest and delete omit vs babel - a lot of different objects
(version: 0)
Comparing performance of:
Lodash vs es omit vs compiled omit vs rest and delete omit vs babel
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.5/lodash.min.js'></script> <script src=''> </script>
Script Preparation code:
var omit1 = (originalObj = {}, keysToOmit = []) => Object.fromEntries( Object.entries(originalObj) .filter(([key]) => !keysToOmit.includes(key)) ) var omit2 = new Function('obj', 'if (!obj) return {}; const { a, d, i, ...res } = obj; return res;'); var omit3 = (originalObject = {}, keysToOmit = []) => { const clonedObject = { ...originalObject }; for (const path of keysToOmit) { delete clonedObject[path] } return clonedObject; } function omit4(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; } function getRandomInt(min, max) { min = Math.ceil(min); max = Math.floor(max); return Math.floor(Math.random() * (max - min) + min); //The maximum is exclusive and the minimum is inclusive } var data = []; for (let i = 0; i < 10000; i++) { const obj = {}; const propsCount = getRandomInt(0, 10); for (let j = 0; j < propsCount; j++) { const propCode = getRandomInt(97, 122); obj[String.fromCharCode(propCode)] = propCode; } data.push(obj); }
Tests:
Lodash
data.map((obj) => _.omit(obj, ['a','d','i']))
es omit
data.map((obj) => omit1(obj, ['a','d','i']))
compiled omit
data.map((obj) => omit2(obj, ['a','d','i']))
rest and delete omit
data.map((obj) => omit3(obj, ['a','d','i']))
babel
data.map((obj) => omit4(obj, ['a','d','i']))
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (5)
Previous results
Fork
Test case name
Result
Lodash
es omit
compiled omit
rest and delete omit
babel
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):
I'll break down the test cases and explain what's being tested, along with their pros and cons. **Test Cases:** 1. **Lodash** The benchmark tests the performance of Lodash's `omit` function, which removes specified properties from an object. The `_.omit` function is called for each object in the `data` array, passing an array of keys to omit (`['a', 'd', 'i']`). This test measures how fast Lodash can perform this operation. Pros: Lodash is a widely-used and well-maintained library, so its implementation is likely efficient. Cons: Since it's a third-party library, there might be some overhead in loading and executing it. 2. **es omit** This benchmark tests the performance of a custom `omit` function implemented using ES6 syntax (notably, arrow functions and destructuring). The function takes an object and an array of keys to omit as arguments. Pros: This implementation is likely to be efficient since it's written in native JavaScript. Cons: Since it's not part of a library or framework, there might be some overhead in loading and executing this code. 3. **compiled omit** This benchmark tests the performance of a custom `omit` function that has been compiled using a JavaScript compiler (in this case, possibly Babel). The function is similar to the ES6 implementation but uses a different syntax. Pros: Compiling the code might improve its performance by optimizing the generated machine code. Cons: There's still some overhead in loading and executing the compiled code. 4. **rest and delete omit** This benchmark tests the performance of a custom `omit` function that uses rest properties (`...`) to extract the omitted properties and then deletes them from the original object using `delete`. Pros: This implementation is likely to be efficient since it avoids creating new objects or arrays. Cons: It might not work in older browsers that don't support rest properties. 5. **babel** This benchmark tests the performance of a custom `omit` function implemented using Babel's syntax (notably, class expressions and arrow functions). The function takes an object and an array of keys to omit as arguments. Pros: This implementation is likely to be efficient since it's written in native JavaScript. Cons: Since it's not part of a library or framework, there might be some overhead in loading and executing this code. **Library/ Framework Considerations:** * Lodash: As mentioned earlier, Lodash is a widely-used and well-maintained library. Its implementation is likely efficient, but there might be some overhead in loading and executing it. * Babel: Babel is used to compile the custom `omit` functions, which might improve their performance by optimizing the generated machine code. **Additional Considerations:** * The test cases are all running on the same environment (Chrome 95), so any differences in performance can be attributed to the implementation or library/framework being tested. * The benchmark is measuring the number of executions per second (`ExecutionsPerSecond` column), which gives an idea of how fast each implementation can process the data. Overall, these test cases provide a good comparison between different implementations and libraries/frameworks for removing properties from objects.
Related benchmarks:
Lodash omit vs es omit vs compiled omit vs rest and delete omit
Lodash omit vs es omit vs compiled omit vs rest and delete omit vs babel
Lodash omit vs es omit vs compiled omit vs rest and delete omit vs babel vs omit as dest and rest - a lot of different objects
Lodash omit vs es omit vs compiled omit vs rest and delete omit vs babel vs omit as dest and rest vs prod version - v1
Comments
Confirm delete:
Do you really want to delete benchmark?