Jak zmierzyć osobno czas dla dwóch funkcji? Chodzi o czasy sortowania dwoma metodami.
0
2
Zmierzyć dla jednej, wypisać, wyzerować i zrobić to samo dla drugiej.
1
Przeklejone z tutorialspoint
#include <stdio.h>
#include <time.h>
int main () {
time_t start_t, end_t;
double diff_t;
printf("Starting of the program...\n");
time(&start_t);
printf("Sleeping for 5 seconds...\n");
sleep(5);
time(&end_t);
diff_t = difftime(end_t, start_t);
printf("Execution time = %f\n", diff_t);
printf("Exiting of the program...\n");
return(0);
}
A w C++ będzie coś takiego, quick and dirty, nie sprawdzałem czy się kompiluje
#include <thread>
#include <chrono>
#include <iostream>
using namespace std::chrono
auto now()
{
return high_resolution_clock::now();
}
void func1()
{
std::this_thread::sleep_for(seconds(5));
}
void func2()
{
std::this_thread::sleep_for(seconds(2));
}
int main()
{
auto f = now();
func1();
std::cout << "func1 time: " << (duration_cast<milliseconds>(now() - f)).count() << "\n";
auto s = now();
func2();
std::cout << "func2 time: " << (duration_cast<milliseconds>(now() - s)).count() << "\n";
return 0;
}
0
Dzięki, udało sie