#include <time.h>
#include <iostream>
using std::cout;
int fib(int n) {
if( n == 0 )
return 0;
else if( n == 1 )
return 1;
else
return fib(n-1)+fib(n-2);
}
int main(int argc, char* argv) {
time_t start_time = time(NULL);
int x = fib(46);
time_t end_time = time(NULL);
cout << "x = " << x << std::endl;
cout << "Total time: " << end_time - start_time << std::endl;
return 0;
}
[legolegs@battlehummer fib]$ g++ -Wall -O3 -o fibcpp fib.cpp
[legolegs@battlehummer fib]$ time ./fibcpp
x = 1836311903
Total time: 20
real 0m20.071s
user 0m18.566s
sys 0m0.075s
Ну и чего?