Test name | Executions per second |
---|---|
destructuring with defaults, empty input | 16394662.0 Ops/sec |
lodash get, empty input | 2589685.0 Ops/sec |
destructuring with defaults, find item | 14848909.0 Ops/sec |
lodash get, find item | 2355672.8 Ops/sec |
destructuring null input | 0.0 Ops/sec |
lodash null input | 9018978.0 Ops/sec |
destructuring undefined input | 0.0 Ops/sec |
lodash undefined input | 8901846.0 Ops/sec |
destructuring dynamic key | 13892219.0 Ops/sec |
lodash dynamic key | 2296507.8 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');