Fibonacci

Compute Fibonacci numbers with recursion, iteration and memoization

benchmarks/fibonacci.bench.tal
///
/// @example "benchmarks/fibonacci.bench.tal"
/// @describe Traces different "fibonacci" benchmarks.
///

// Talos Modules
import "talos:test" as Test;

// - TEST SETUP - //

export let fibonacci = fn (n: Number): Number {
    if (n < 2) return n;
    return ^(n - 2) + ^(n - 1);
};

// - TEST CASES - //

Test.bench("fibonacci", fn => fibonacci(25));

On this page