<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
var n = 10000;
var o = {};
while (n) {
o["entry"+ n] = true;
n--;
}
_.omit(o, "entry1", "entry2", "entry3", "entry4", "entry5", "entry6", "entry7", "entry8", "entry9", "entry10");
const {entry1, entry2, entry3, entry4, entry5, entry6, entry7, entry8, entry9, entry10, props} = o;
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Lodash Omit | |
ES6 spread |
Test name | Executions per second |
---|---|
Lodash Omit | 582.9 Ops/sec |
ES6 spread | 365.5 Ops/sec |
Let's break down the provided benchmark definition and test cases.
Benchmark Definition
The benchmark is comparing two approaches to omit certain properties from an object:
omit
function:_.omit(o, "entry1", "entry2", ...);
This function creates a new object that includes all the properties of o
except those specified in the array.
...props
) to omit properties:const { entry1, entry2, ..., props } = o;
In this approach, the spread operator is used to extract all properties from o
into an object called props
, except for the ones specified in the array.
Options Compared
The two options being compared are:
omit
function...props
)Pros and Cons of Each Approach
omit
FunctionPros:
Cons:
lodash
) to be set up before running the test.Pros:
Cons:
Other Considerations
omit
function potentially using more memory due to the creation of a new object.Library Used (Lodash)
The Lodash library is a popular JavaScript utility library that provides a wide range of functions for tasks such as array manipulation, object creation, and more. In this benchmark, the omit
function is used to filter out certain properties from an object.
Special JS Feature/Syntax
There are no special JavaScript features or syntaxes being tested in this benchmark. Both approaches use standard JavaScript syntax and libraries (Lodash for the first approach).