Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
fibonacci Recursive vs Memoization
(version: 0)
Comparing performance of:
Recursive vs Memoization
Created:
3 years ago
by:
Guest
Jump to the latest result
Tests:
Recursive
function fibonacciRecursive(num) { if (num === 0) return 0; else if (num === 1) return 1; else return fibonacciRecursive(num - 1) + fibonacciRecursive(num - 2); //i[n] = i[n-1] + i[n-2] } fibonacciRecursive(10)
Memoization
function fibonacciRecursiveObjDefault(num, cache = {}) { //base case as normal if (num === 0) return 0; else if (num === 1) return 1; if (cache[num]) return cache[num]; //retrieve cached data if exists let output = fibonacciRecursiveObjDefault(num - 1, cache) + fibonacciRecursiveObjDefault(num - 2, cache); //recursive call as normal cache[num] = output; //store output into the cache for future use return output; } fibonacciRecursiveObjDefault(10)
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (2)
Previous results
Fork
Test case name
Result
Recursive
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):
**Benchmark Overview** The provided JSON represents a JavaScript benchmark test case, specifically comparing the performance of two approaches to calculate the Fibonacci sequence: recursive and memoization. **Test Cases** There are two individual test cases: 1. **Recursive**: This test case measures the execution time of the traditional recursive approach to calculate the Fibonacci sequence. 2. **Memoization**: This test case measures the execution time of a modified recursive approach that uses memoization (caching) to store previously computed values, reducing redundant calculations. **Options Compared** The two approaches are compared in terms of their execution times. Memoization is expected to outperform the traditional recursive approach due to its caching mechanism, which reduces the number of repeated computations. **Pros and Cons** * **Recursive Approach:** + Pros: - Simple to implement. - Intuitive for understanding the Fibonacci sequence calculation. + Cons: - Inefficient due to redundant calculations (e.g., `fibonacciRecursive(10)` calls `fibonacciRecursive(9)` twice). * **Memoization Approach:** + Pros: - Reduces redundant calculations by caching previously computed values. - Can lead to significant performance improvements for large inputs. + Cons: - Adds additional memory usage for storing cached data. - Requires more complex implementation. **Library/Extension** None mentioned in the provided JSON. **Special JS Feature/Syntax** No special JavaScript features or syntax are used in these test cases. They only employ basic programming concepts, such as function definitions and loops. **Alternatives** Other approaches to calculating the Fibonacci sequence could include: 1. **Iterative Approach**: Using a loop to calculate the Fibonacci sequence without recursion. 2. **Dynamic Programming**: Using a table to store intermediate results, similar to memoization but with additional overhead for maintaining the table. 3. **Matrix Exponentiation**: Using matrix multiplication to efficiently calculate the Fibonacci sequence for large inputs. These alternative approaches might be explored in other benchmark test cases or as part of more comprehensive performance comparisons.
Related benchmarks:
Fib Now2
Fib Now 3
Fib Now 4
Generator vs function
Comments
Confirm delete:
Do you really want to delete benchmark?