Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Destructuring test 2
(version: 0)
Comparing performance of:
A vs B vs C vs D
Created:
6 years ago
by:
Guest
Jump to the latest result
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);
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
A
B
C
D
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
I'll break down the provided JSON and explain what's being tested, compared options, pros and cons of each approach, and other considerations. **Benchmark Definition** The benchmark definition is a JavaScript code snippet that tests three different functions for deconstructing objects: 1. `_objectWithoutPropertiesLoose` (loose object properties) 2. `_altGenerated` (alternative generated function) 3. `manual` (manually removing properties) 4. `manual2` (an alternative implementation of manual) The benchmark definition is a combination of the four functions, executed in sequence with different input objects (`a`, `b`, and `c`). **Options being compared** The options being compared are: 1. **Loose object properties**: `_objectWithoutPropertiesLoose` * Pros: Simple to implement, widely supported. * Cons: May not cover all edge cases. 2. **Alternative generated function**: `_altGenerated` * Pros: More flexible than loose object properties, covers more edge cases. * Cons: More complex implementation, may be slower due to function call overhead. 3. **Manual removal of properties**: `manual` and `manual2` * Pros: Can cover most edge cases, allows for fine-grained control over removal logic. * Cons: More complex implementation, may lead to performance issues if not optimized. **Other considerations** * The benchmark uses Firefox Mobile 48 as the browser, running on Android devices with Firefox OS. * The `ExecutionsPerSecond` metric indicates the number of executions per second, which is a good indicator of performance. * The results show that the `_altGenerated` function outperforms both manual implementations (`manual` and `manual2`) in terms of execution speed. **Benchmark Results** The latest benchmark result shows that: 1. **B**: `_altGenerated` performs best with an average execution speed of 88774 executions per second. 2. **C**: Manual implementation (`manual`) is slightly slower than `_altGenerated`, with an average execution speed of 43358 executions per second. 3. **D**: The alternative manual implementation (`manual2`) is the slowest, with an average execution speed of 19454 executions per second. 4. **A**: The loose object properties approach is the slowest, with an average execution speed of 43358 executions per second. Overall, the results suggest that `_altGenerated` provides a good balance between performance and flexibility in deconstructing objects, making it a recommended approach for this benchmark.
Related benchmarks:
Destructuring test
Destructuring test!
withoutObjectKeys again
withoutObjectKeys again and again
Comments
Confirm delete:
Do you really want to delete benchmark?