Liste des Groupes | Revenir à cl c++ |
<+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>
#include <iostream>
#include <chrono>
int fibonacci(int n)
{
if (n <= 1)
return n;
return fibonacci(n - 2) + fibonacci(n - 1);
}
constexpr int fibonacci_c(int n)
{
if (n <= 1)
return n;
return fibonacci_c(n - 2) + fibonacci_c(n - 1);
}
int main(void)
{
// using namespace std::literals::chrono_literals;
auto start = std::chrono::high_resolution_clock::now();
constexpr int num = 35;
/*constexpr*/ int result_c = fibonacci_c(num);
std::cout << "Fibonacci_c " << result_c << "\n";
std::cout << "Time taken: " <<
std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now()
- start).count() << "\n";
start = std::chrono::high_resolution_clock::now();
int result = fibonacci(num);
std::cout << "Fibonacci " << result << "\n";
std::cout << "Time taken: " <<
std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now()
- start).count() << "\n";
}
<+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Les messages affichés proviennent d'usenet.