Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
Function execution time check for memoization
(version: 0)
Comparing performance of:
Without memoizastion vs With Memoization
Created:
6 years ago
by:
Guest
Jump to the latest result
HTML Preparation code:
<script src="https://cdn.jsdelivr.net/npm/lodash@4.17.4/lodash.min.js"></script>
Tests:
Without memoizastion
const getSettingValues = config => config.values; const showPrimaryProfile = config => { const enabledChannels = _.union(getSettingValues(config), ['a']); return _.includes(enabledChannels, ['b']); } _.times(1000, () => { showPrimaryProfile({values: ['z']}); })
With Memoization
const getSettingValues = config => config.values; const getEnabledChannels = _.memoize(config => _.union(config, ['a'])) const showPrimaryProfile = config => { const enabledChannels = getEnabledChannels(getSettingValues(config)); return _.includes(enabledChannels, ['b']); } _.times(1000, () => { showPrimaryProfile({values: ['z']}); })
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Without memoizastion
With Memoization
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 break down what's being tested on MeasureThat.net. The provided JSON represents two benchmark test cases for measuring the execution time of JavaScript functions with memoization. **Memoization**: Memoization is an optimization technique where the result of a function is cached and reused when the same inputs occur again. This can significantly speed up performance-critical code by avoiding redundant calculations. **Options being compared:** 1. **Without memoization**: The first test case measures the execution time of the `showPrimaryProfile` function without using memoization. 2. **With memoization**: The second test case measures the execution time of the same `showPrimaryProfile` function, but with memoization enabled through the use of the `_memoize` function from the Lodash library. **Pros and cons:** * **Without memoization**: This approach does not cache results, which means that each call to `showPrimaryProfile` will recalculate the entire expression, leading to slow performance. However, this approach is simple to implement and understand. * **With memoization**: This approach caches results, which can significantly speed up performance-critical code. However, memoization also introduces additional overhead for caching and updating cache entries. **Lodash library:** The Lodash library is a popular JavaScript utility library that provides various functions for tasks such as array manipulation, object iteration, and more. In this benchmark, the `_memoize` function is used to enable memoization in the `showPrimaryProfile` function. * **Purpose of _memoize**: The `_memoize` function takes a function as an argument and returns a new function that caches the result of the original function. When the same inputs are passed again, the cached result is returned instead of recalculating it. **Special JS feature or syntax:** There is no special JavaScript feature or syntax being tested in this benchmark. The code uses standard JavaScript syntax and libraries (Lodash) to demonstrate memoization. Other alternatives: * If memoization were not an option, alternative optimizations could include: + Caching results using a hash table or object. + Using a just-in-time (JIT) compiler to optimize performance-critical code. + Breaking down complex functions into smaller, more manageable pieces. * If the `showPrimaryProfile` function were rewritten without memoization, other approaches might include: + Recalculating the entire expression on each call. + Using a different data structure (e.g., a tree or graph) to represent the calculation. Overall, this benchmark demonstrates the benefits of memoization in improving performance-critical code execution times.
Related benchmarks:
memoizeOne
memoizeOne - complex types
memoizeOne - September 2020
memoizeOne - complex types - September 2020
memoize-one vs fast-memoize not-repeating--previous
Comments
Confirm delete:
Do you really want to delete benchmark?