SOURCE

let deepCache = {};

function Fib(num){
    if(num == 1 || num == 2) return 1;
    
    // 如果计算过直接返回
    if(deepCache[num]) return deepCache[num];

    return deepCache[num] = Fib(num - 1) + Fib(num - 2);
}

console.time();
console.log(Fib(7)); // 354224848179262000000
console.timeEnd(); //  0.145751953125ms
console 命令行工具 X clear

                    
>
console