53 lines
1.6 KiB
C++
53 lines
1.6 KiB
C++
#include "bsp_1_c.h"
|
|
#include <iostream>
|
|
#include <chrono>
|
|
// BSP 1_C
|
|
using namespace std;
|
|
|
|
int main()
|
|
{
|
|
long long int n1 = 15;
|
|
long long int n2 = 1001;
|
|
long long int n3 = 1432987;
|
|
|
|
cout << "n = " << n1 << endl;
|
|
cout << "Funktion 1 / loops" << endl;
|
|
cout << fkt1(n1) << endl;
|
|
cout << "Funktion 2 / Formel" << endl;
|
|
cout << fkt2(n1) << endl << endl;
|
|
|
|
cout << "n = " << n2 << endl;
|
|
cout << "Funktion 1 / loops" << endl;
|
|
cout << fkt1(n2) << endl;
|
|
cout << "Funktion 2 / Formel" << endl;
|
|
cout << fkt2(n2) << endl << endl;
|
|
|
|
cout << "n = " << n3 << endl;
|
|
cout << "Funktion 1 / loops" << endl;
|
|
cout << fkt1(n3) << endl;
|
|
cout << "Funktion 2 / Formel" << endl;
|
|
cout << fkt2(n3) << endl << endl;
|
|
|
|
|
|
// ad Zeitmessung beider Funktionen
|
|
auto time1start = std::chrono::system_clock::now();
|
|
for (int k = 1; k <= 10000; ++k)
|
|
{
|
|
fkt1(n3);
|
|
}
|
|
auto time1end = std::chrono::system_clock::now();
|
|
auto time1 = std::chrono::duration_cast<std::chrono::milliseconds>(time1end - time1start);
|
|
cout << "benoetigte Zeit fuer Funktion 1 (10000 maliger Aufruf; n=1432987): " << time1.count() << "ms" << endl;
|
|
|
|
auto time2start = std::chrono::system_clock::now();
|
|
for (int k = 1; k <= 10000; ++k)
|
|
{
|
|
fkt2(n3);
|
|
}
|
|
auto time2end = std::chrono::system_clock::now();
|
|
auto time2 = std::chrono::duration_cast<std::chrono::milliseconds>(time2end - time2start);
|
|
cout << "benoetigte Zeit fuer Funktion 2 (10000 maliger Aufruf; n=1432987): " << time2.count() << "ms" << endl;
|
|
|
|
|
|
return 0;
|
|
}
|