<script src="https://cdn.jsdelivr.net/lodash/4/lodash.min.js"></script>
function destructuringFn(input) {
const { contextMenu: { data: { documents = [] } = {} } = {} } = input;
return documents;
}
function destructuringFnDynamic(input, key) {
const { contextMenu: { data: { [key]: documents = [] } = {} } = {} } = input;
return documents;
}
function lodashFn(input) {
const documents = _.get(input, 'contextMenu.data.documents', []);
return documents;
}
function lodashFnDynamic(input, key) {
const documents = _.get(input, `contextMenu.data.${key}`, []);
return documents;
}
function oldWay(input, key) {
const documents = _.get(input, `contextMenu.data.${key}`, []);
return input && input.contextMenu && input.contextMenu.data && input.contextMenu.data[key];
}
function test(fn, input, key) {
fn(input, key);
}
test(destructuringFn, {});
test(lodashFn, {});
const input = { contextMenu: { data: { documents: [{ id: 'doc' }] } } };
test(destructuringFn, input);
const input = { contextMenu: { data: { documents: [{ id: 'doc' }] } } };
test(lodashFn, input);
test(destructuringFn, null);
test(lodashFn, null);
let input;
test(destructuringFn, input);
let input;
test(lodashFn, input);
const input = { contextMenu: { data: { documents: [{ id: 'doc' }] } } };
test(destructuringFn, input, 'documents');
const input = { contextMenu: { data: { documents: [{ id: 'doc' }] } } };
test(lodashFn, input, 'documents');
const input = { contextMenu: { data: { documents: [{ id: 'doc' }] } } };
test(oldWay, input, 'documents');
--enable-precise-memory-info
flag.
Test case name | Result |
---|---|
destructuring with defaults, empty inputa | |
lodash get, empty inputb | |
destructuring with defaults, find item | |
lodash get, find item | |
destructuring null input | |
lodash null input | |
destructuring undefined input | |
lodash undefined input | |
destructuring dynamic key | |
lodash dynamic key | |
oldway |
Test name | Executions per second |
---|---|
destructuring with defaults, empty inputa | 7237581.5 Ops/sec |
lodash get, empty inputb | 2018020.1 Ops/sec |
destructuring with defaults, find item | 2166894.2 Ops/sec |
lodash get, find item | 1132740.8 Ops/sec |
destructuring null input | 0.0 Ops/sec |
lodash null input | 3630878.8 Ops/sec |
destructuring undefined input | 0.0 Ops/sec |
lodash undefined input | 3624121.2 Ops/sec |
destructuring dynamic key | 2310019.8 Ops/sec |
lodash dynamic key | 1205071.4 Ops/sec |
oldway | 908986.2 Ops/sec |
It looks like you've provided a large JSON array of browser performance data, but without the actual values being compared or analyzed, it's difficult to provide specific insights.
However, I can suggest some possible ways to analyze this data:
To help you better analyze this data, I can ask some follow-up questions:
Please provide more context or details about your project, and I'll do my best to assist you in analyzing this data.