1 const Benchmark
= require('benny')
9 function fibonacciLoop (num
) {
28 function fibonacciRecursion (num
) {
29 if (num
<= 1) return 1
31 return fibonacciRecursion(num
- 1) + fibonacciRecursion(num
- 2)
39 function fibonacciRecursionMemoization (num
, memo
) {
42 if (memo
[num
]) return memo
[num
]
43 if (num
<= 1) return 1
46 fibonacciRecursionMemoization(num
- 1, memo
) +
47 fibonacciRecursionMemoization(num
- 2, memo
))
51 `Fibonacci number ${number}`,
52 Benchmark
.add('fibonacciLoop', () => {
55 Benchmark
.add('fibonacciRecursion', () => {
56 fibonacciRecursion(number
)
58 Benchmark
.add('fibonacciRecursionMemoization', () => {
59 fibonacciRecursionMemoization(number
)
63 Benchmark
.save({ file
: 'fibonacci', format
: 'json', details
: true }),
64 Benchmark
.save({ file
: 'fibonacci', format
: 'chart.html', details
: true }),
65 Benchmark
.save({ file
: 'fibonacci', format
: 'table.html', details
: true })