<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) {
return input && input.contextMenu && input.contextMenu.data && input.contextMenu.data[key];
}
function straight(input, key) {
return 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 | 7405322.0 Ops/sec |
lodash get, empty inputb | 2027121.1 Ops/sec |
destructuring with defaults, find item | 2183288.0 Ops/sec |
lodash get, find item | 1142467.6 Ops/sec |
destructuring null input | 0.0 Ops/sec |
lodash null input | 3629445.0 Ops/sec |
destructuring undefined input | 0.0 Ops/sec |
lodash undefined input | 3604285.0 Ops/sec |
destructuring dynamic key | 2277015.0 Ops/sec |
lodash dynamic key | 1190928.6 Ops/sec |
oldway | 2326937.5 Ops/sec |
Let's dive into the data.
It appears to be a collection of browser usage metrics, likely from a testing or monitoring scenario. Here are some observations:
lodash undefined input
, destructuring dynamic key
, etc.).If you'd like to know more about the data or would like me to extract specific insights, please let me know!