Destructuring test 2
Date tested:
4 years ago
User agent:
Mozilla/5.0 (Mobile; LYF/LF-2403N/LYF-LF2403N-001-02-09-010618-i;Android; rv:48.0) Gecko/48.0 Firefox/48.0 KAIOS/2.5
Test name
Executions per second
A
19454.9 Ops/sec
B
107475.2 Ops/sec
C
88774.0 Ops/sec
D
43358.8 Ops/sec
Benchmark definition (click to collapse):
Script Preparation code:
var a = {bla: 1, heyo: 2, afdsda: 3, innerRef: 4, ad: 5}; var b = {hasFocusPriority: 1, heyo: 2, afdsda: 3, innerRef: 4, ad: 5}; var c = {hasFocusPriority: 1, ref: 2, onFocus: 3, innerRef: 4, onNativeBlur: 5}; function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } function _altGenerated(target, source, excluded) { for (var key in source) { if (!excluded(key)) target[key] = source[key]; } return target; } function destructure(props) { return Object.assign( {ref: 1, onFocus: 2, onBlur: 3}, _objectWithoutPropertiesLoose(props, [ 'innerRef', 'hasFocusPriority', 'ref', 'onFocus', 'onBlur', 'onNativeFocus', 'onNativeBlur', ]) ); } function destructureAlt(props) { return _altGenerated( {ref: 1, onFocus: 2, onBlur: 3}, props, key => key === 'innerRef' || key === 'hasFocusPriority' || key === 'ref' || key === 'onFocus' || key === 'onBlur' || key === 'onNativeFocus' || key === 'onNativeBlur' ); } function manual(props) { var childProps = { ref: 1, onFocus: 2, onBlur: 3, }; for (let key in props) { switch (key) { case 'innerRef': case 'hasFocusPriority': case 'ref': // I do not know if this one could happen case 'onFocus': case 'onBlur': case 'onNativeFocus': case 'onNativeBlur': break; default: childProps[key] = props[key]; } } return childProps; } function manual2(props) { var childProps = { ref: 1, onFocus: 2, onBlur: 3, }; let keys = Object.keys(props); for (let i = 0; i < keys.length; i++) { let key = keys[i]; switch (key) { case 'innerRef': case 'hasFocusPriority': case 'ref': // I do not know if this one could happen case 'onFocus': case 'onBlur': case 'onNativeFocus': case 'onNativeBlur': break; default: childProps[key] = props[key]; } } return childProps; }
Tests:
A
destructure(a); destructure(b); destructure(c);
B
destructureAlt(a); destructureAlt(b); destructureAlt(c);
C
manual(a); manual(b); manual(c);
D
manual2(a); manual2(b); manual2(c);
Open this result on MeasureThat.net