Test name | Executions per second |
---|---|
destructuring with defaults, empty input | 6999576.5 Ops/sec |
lodash get, empty input | 1579507.5 Ops/sec |
destructuring with defaults, find item | 2261555.2 Ops/sec |
lodash get, find item | 918810.1 Ops/sec |
destructuring null input | 0.0 Ops/sec |
lodash null input | 2852863.8 Ops/sec |
destructuring undefined input | 0.0 Ops/sec |
lodash undefined input | 2832999.5 Ops/sec |
destructuring dynamic key | 1661328.9 Ops/sec |
lodash dynamic key | 938418.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');