1 import { bench, group, run } from 'tatami-ng'
9 function fibonacciLoop (num) {
13 for (let i = 2; i <= num; i++) {
14 fib[i] = fib[i - 2] + fib[i - 1]
24 function fibonacciLoopWhile (num) {
39 function fibonacciRecursion (num) {
40 if (num <= 1) return num
41 return fibonacciRecursion(num - 1) + fibonacciRecursion(num - 2)
49 function fibonacciRecursionMemoization (num, memo) {
52 if (memo[num]) return memo[num]
53 if (num <= 1) return num
56 fibonacciRecursionMemoization(num - 1, memo) +
57 fibonacciRecursionMemoization(num - 2, memo))
60 group(`Fibonacci number ${number}`, () => {
61 bench('fibonacciLoop', () => {
64 bench('fibonacciLoopWhile', () => {
65 fibonacciLoopWhile(number)
67 bench('fibonacciRecursion', () => {
68 fibonacciRecursion(number)
70 bench('fibonacciRecursionMemoization', () => {
71 fibonacciRecursionMemoization(number)