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 vs omit as dest and rest - a lot of different objects
(version: 0)
Comparing performance of:
Lodash vs es omit vs compiled omit vs rest and delete omit vs babel vs dest and rest
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']))
dest and rest
data.map((obj) => { const { a, d, i, ...rest } = obj; return rest; })
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (6)
Previous results
Fork
Test case name
Result
Lodash
es omit
compiled omit
rest and delete omit
babel
dest and rest
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 benchmark and its various components. **Benchmark Overview** The provided JSON represents a JavaScript microbenchmarking test created on MeasureThat.net. The benchmark compares the performance of different approaches for removing properties from objects. **Options Compared** 1. **Lodash**: A popular JavaScript utility library that provides various functions, including `omit()`, which removes specified keys from an object. 2. **ES omit (es omit)**: A built-in JavaScript method to remove properties from an object using the spread operator (`{...obj} - {a, d, i}`) 3. **Compiled omit (compiled omit)**: An approach that compiles a function that creates a new object with only the desired properties, avoiding the use of `Object.fromEntries()` or `Object.assign()`. 4. **Rest and delete omit**: An approach that uses destructuring to extract only the desired properties from an object and then deletes the unwanted properties. 5. **Babel**: A popular JavaScript transpiler that can also be used as a library for minification and other tasks. 6. **Dest and rest (dest and rest)**: A concise way of removing properties from an object using destructuring. **Pros and Cons** 1. **Lodash omit**: * Pros: Easy to use, well-maintained, and widely supported. * Cons: May have performance overhead due to its function call and the need for imports. 2. **ES omit (es omit)**: * Pros: Lightweight, fast, and built-in. * Cons: Only works with recent JavaScript engines that support this syntax. 3. **Compiled omit (compiled omit)**: * Pros: Fast and lightweight, as it avoids function call overhead. * Cons: Requires manual implementation and may be less readable for some developers. 4. **Rest and delete omit**: * Pros: Concise and easy to understand, avoiding unnecessary function calls or object creations. * Cons: May not work with older JavaScript engines that do not support destructuring. 5. **Babel**: * Pros: Provides various optimization options for minification and other tasks. * Cons: Adds dependency on the Babel library and may introduce overhead due to transpilation. 6. **Dest and rest (dest and rest)**: * Pros: Concise and easy to understand, providing a good balance between readability and performance. * Cons: May not work with older JavaScript engines that do not support destructuring. **Performance Results** The provided results show the execution rate per second for each approach on a Chrome 93 browser. The top performer is **Rest and delete omit**, followed by **Compiled omit (compiled omit)**, and then **ES omit (es omit)**. In summary, this benchmarking test helps developers understand the performance characteristics of different approaches for removing properties from objects in JavaScript. It highlights the importance of choosing an approach that balances readability with performance requirements.
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 - 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?