Imagine you have a TypeScript object with the possibility of elements being undefined. Navigating through a deeply nested structure requires multiple comparisons against undefined values.
I wanted to examine the performance difference between using regular if-else statements and the lodash function get for this purpose.
I recently came across a tool known as "jsben" that allows benchmarking different JavaScript code snippets. However, I am struggling to properly interpret the results.
In a specific test, it appears that lodash get is slightly faster. But in another scenario (see here), when the variable is defined in the Setup block instead of the Boilerplate code, the if-else approach outperforms by a significant margin.
What is the correct method for accurately benchmarking these techniques? How should one make sense of the findings? Given the potential readability issues, is the improved speed enough to advocate for if-else statements over using get from lodash?