Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Recursion1
(version: 1)
Comparing performance of:
deactivateAllNestedShowProperties(showable1) vs deactivateAllNestedShowProperties(showable2)
Created:
4 years ago
by:
Registered User
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/lodash/4.16.0/lodash.min.js"></script>
Script Preparation code:
var showable1 = { show: true, showable1: {show: true } }; var showable2 = { show: true, showable1: { show: true, showable2: { show: true, showable3: { show: true, showable4: { show: true, showable5: { show: true, showable6: { show: true, showable7: { show: true, showable8: { show: true, showable9: { show: true, showable10: { show: true, showable11: { show: true, showable12: { show: true, showable13: { show: true, showable14: { show: true, showable15: { show: true, showable16: { show: true, showable17: { show: true, showable18: { show: true, showable19: { show: true, showable20: { show: true } }, }, }, }, }, }, }, }, }, }, }, }, }, }, }, }, }, }, }, }; function deactivateAllNestedShowProperties (showable) { if (showable.show) { showable.show = false; } for (var key in showable) { var nestedShowable = showable[key]; if (_.isObject(nestedShowable)) { deactivateAllNestedShowProperties(nestedShowable); } } }
Tests:
deactivateAllNestedShowProperties(showable1)
deactivateAllNestedShowProperties(showable1)
deactivateAllNestedShowProperties(showable2)
deactivateAllNestedShowProperties(showable2)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
deactivateAllNestedShowProperties(showable1)
deactivateAllNestedShowProperties(showable2)
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):
Let's dive into the world of JavaScript microbenchmarks on MeasureThat.net. **Benchmark Definition JSON** The provided JSON defines a benchmark named "Recursion1" with two test cases: `deactivateAllNestedShowProperties(showable1)` and `deactivateAllNestedShowProperties(showable2)`. The script preparation code creates two objects, `showable1` and `showable2`, which are nested deep within each other. **Script Preparation Code** The script preparation code defines an object `showable1` with a property `showable1` that contains another object. Similarly, `showable2` is defined as a nested object within `showable1`. The code also includes the Lodash library via a CDN link in the HTML preparation code. **Html Preparation Code** The HTML preparation code includes a script tag that loads the Lodash library from a CDN. **Deactivate All Nested Show Properties Function** The function `deactivateAllNestedShowProperties(showable)` is used to recursively deactivate all nested show properties. It checks if the current property has a value of `true` and sets it to `false`. Then, it loops through each property in the object and calls itself recursively on any objects found. **Library: Lodash** Lodash is a popular JavaScript utility library that provides a wide range of functions for tasks such as data manipulation, string manipulation, and more. In this benchmark, Lodash is used to check if an object is an instance of `lodash.Object` (i.e., an actual object) before calling the recursive function. **Pros and Cons** * Pros: + Recursively deactivates all nested show properties, which can be useful in certain scenarios. + Uses a standard library like Lodash, making it easier to maintain and compare results across different environments. * Cons: + Can lead to performance issues if the recursion is too deep or if the object structure is complex. + May not be suitable for all use cases, especially those with very large or deeply nested objects. **Other Alternatives** If you were to rewrite this benchmark without using Lodash, you could: 1. Use a simple recursive function that checks each property manually instead of relying on Lodash's `isObject` function. 2. Use a different library like `lodash.isPlainObject` or implement your own logic for checking if an object is plain. 3. Consider rewriting the code to avoid recursion altogether and use iterative methods instead. **Special JS Features/Syntax** There are no special JavaScript features or syntaxes used in this benchmark that would be unfamiliar to most software engineers. However, it's worth noting that MeasureThat.net supports testing various JavaScript features like async/await, Promises, and more. Overall, this benchmark provides a good example of how to create a recursive function in JavaScript and test its performance with different input objects. By using Lodash, the benchmark can focus on comparing the execution times of the `deactivateAllNestedShowProperties` function across different environments.
Related benchmarks:
loop count
loop count
Object.keys filter vs Object.values reduce
Lodash isEqual test vs Custom Recursive Function
Comments
Confirm delete:
Do you really want to delete benchmark?