diff --git a/benchmarks/fib_dynamic.cdc b/benchmarks/fib_dynamic.cdc index ac608f3c4..55248afa1 100644 --- a/benchmarks/fib_dynamic.cdc +++ b/benchmarks/fib_dynamic.cdc @@ -17,5 +17,5 @@ fun fib(_ n: Int): Int { access(all) fun main() { - assert(fib(14) == 377) -} \ No newline at end of file + assert(fib(23) == 28657) +} diff --git a/benchmarks/fib_iterative.cdc b/benchmarks/fib_iterative.cdc new file mode 100644 index 000000000..a7a162270 --- /dev/null +++ b/benchmarks/fib_iterative.cdc @@ -0,0 +1,19 @@ +access(all) +fun fib(_ n: Int): Int { + var fib1 = 1 + var fib2 = 1 + var fibonacci = fib1 + var i = 2 + while i < n { + fibonacci = fib1 + fib2 + fib1 = fib2 + fib2 = fibonacci + i = i + 1 + } + return fibonacci +} + +access(all) +fun main() { + assert(fib(23) == 28657) +} diff --git a/benchmarks/fib_recursive.cdc b/benchmarks/fib_recursive.cdc new file mode 100644 index 000000000..5b06a75a4 --- /dev/null +++ b/benchmarks/fib_recursive.cdc @@ -0,0 +1,12 @@ +access(all) +fun fib(_ n: Int): Int { + if n < 2 { + return n + } + return fib(n - 1) + fib(n - 2) +} + +access(all) +fun main() { + assert(fib(23) == 28657) +}