#include #include #include #include"cachable.h" using namespace std; typedef long long vtype; std::function fib = cachable::cachable([](vtype n)->vtype { if (n<2) return 1; return fib(n-1)+fib(n-2); }); int main(int argc, char **argv) { vtype i = argc>1 ? atol(argv[1]) : 1000000; struct rlimit rlim; getrlimit(RLIMIT_STACK,&rlim); rlim.rlim_cur = 1450*i; setrlimit(RLIMIT_STACK,&rlim); auto start = chrono::high_resolution_clock::now(); vtype ans = fib(i); auto end = chrono::high_resolution_clock::now(); cout << "ans = " << ans << endl; cout << "time = " << chrono::duration_cast(end-start).count() << " ms" << endl; }