Advertisement
Guest User

Untitled

a guest
May 8th, 2021
626
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. // g++ -O2 -fdiagnostics-color=always fib.cpp -o /tmp/fib;clang++ -O2 -fdiagnostics-color=always fib.cpp -o /tmp/fib2;/tmp/fib;/tmp/fib2
  2. // Value: 20365011073
  3. // Execution time: 37.622s
  4. // Value: 20365011073
  5. // Execution time: 61.858s
  6.  
  7.  
  8. #include <chrono>
  9. #include <iostream>
  10.  
  11.  
  12. uint64_t fibonachi(uint64_t n) {
  13.     if (n <= 1)
  14.         return n;
  15.  
  16.     return fibonachi(n - 1) + fibonachi(n - 2);
  17. }
  18.  
  19.  
  20. int main() {
  21.  
  22.     uint64_t fib = 0;
  23.  
  24.     auto start = std::chrono::high_resolution_clock::now();
  25.  
  26.     for (size_t i = 0; i < 50; i++) {
  27.         fib += fibonachi(i);
  28.     }
  29.  
  30.     auto stop = std::chrono::high_resolution_clock::now();
  31.     auto duration = std::chrono::duration_cast<std::chrono::microseconds>(stop - start);
  32.  
  33.     std::cout << "Value: " << fib << std::endl;
  34.     std::cout << "Execution time: " << (duration.count() / 1000000.0f) << "s" << std::endl;
  35.  
  36.     return 0;
  37.  
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement