<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
<script src=''>
</script>
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 omitProd(src) {
if (!src || typeof src !== 'object') return {};
const clonedObject = { src };
let idx = 0;
let propsList = arguments;
if (Array.isArray(propsList[1])) {
propsList = propsList[1];
idx = -1;
}
const len = propsList.length;
while (++idx < len) {
const key = propsList[idx];
delete clonedObject[key];
}
return clonedObject;
}
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);
}
data.map((obj) => _.omit(obj, ['a','d','i']))
data.map((obj) => omit1(obj, ['a','d','i']))
data.map((obj) => omit2(obj, ['a','d','i']))
data.map((obj) => omit3(obj, ['a','d','i']))
data.map((obj) => omit4(obj, ['a','d','i']))
data.map((obj) => { const { a, d, i, rest } = obj; return rest; })
data.map((obj) => omitProd(obj, 'a','d','i'))
data.map((obj) => omitProd(obj, ['a','d','i']))
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
Lodash | |
es omit | |
compiled omit | |
rest and delete omit | |
babel | |
dest and rest | |
prod version | |
prod version array |
Test name | Executions per second |
---|---|
Lodash | 41.1 Ops/sec |
es omit | 144.9 Ops/sec |
compiled omit | 89.5 Ops/sec |
rest and delete omit | 198.7 Ops/sec |
babel | 118.2 Ops/sec |
dest and rest | 96.2 Ops/sec |
prod version | 145.2 Ops/sec |
prod version array | 141.5 Ops/sec |
A daunting task!
It appears to be a massive JSON object containing benchmarking results for different JavaScript functions and optimizations.
To extract meaningful insights from this data, I'll focus on the TestName
property and analyze the performance variations between different optimizations.
Benchmark Name Variations
delete
operator.obj.delete('property')
).delete
operator.Performance Insights
Comparing the execution speeds across different optimizations and test names reveals some interesting patterns:
rest and delete omit
and es omit
tend to have similar performance, suggesting that both approaches are efficient for removing properties.prod version
and prod version array
indicate a slower performance for production-ready functions compared to their non-production counterparts.babel
benchmark shows a significant slowdown due to the transpilation process.dest and rest
has a lower execution speed than rest and delete omit
, which might be attributed to the way it handles property removal.Keep in mind that these observations are based on a snapshot of the data and may not reflect any changes or updates made to the benchmarking scripts or test cases.