Test name | Executions per second |
---|---|
destructuring with defaults, empty input | 7072968.0 Ops/sec |
lodash get, empty input | 1993970.4 Ops/sec |
destructuring with defaults, find item | 1943352.0 Ops/sec |
lodash get, find item | 1080729.5 Ops/sec |
destructuring null input | 0.0 Ops/sec |
lodash null input | 3635433.2 Ops/sec |
destructuring undefined input | 0.0 Ops/sec |
lodash undefined input | 3626903.2 Ops/sec |
destructuring dynamic key | 2130818.8 Ops/sec |
lodash dynamic key | 1159401.1 Ops/sec |
<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 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');