fork download
  1. #include <iostream>
  2. #include <chrono>
  3. #include <ctime>
  4.  
  5. int fibonacci(int n)
  6. {
  7. if (n < 3) return 1;
  8. return fibonacci(n-1) + fibonacci(n-2);
  9. }
  10.  
  11. int main()
  12. {
  13. std::chrono::time_point<std::chrono::system_clock> start, end;
  14. start = std::chrono::system_clock::now();
  15. int result = fibonacci(42);
  16. end = std::chrono::system_clock::now();
  17.  
  18. int elapsed_seconds = std::chrono::duration_cast<std::chrono::nanoseconds>
  19. (end-start).count();
  20. std::time_t end_time = std::chrono::system_clock::to_time_t(end);
  21.  
  22. std::cout << "finished computation at " << std::ctime(&end_time)
  23. << "elapsed time: " << elapsed_seconds << "ns\n";
  24. }
Success #stdin #stdout 1.24s 3016KB
stdin
Standard input is empty
stdout
finished computation at Fri Aug 10 03:26:55 2012
elapsed time: 1239804000ns