I made a program that randomly generates a vector and then orders it, using bubble sort, now I have to measure the time spent with the ordering.
I made a program that randomly generates a vector and then orders it, using bubble sort, now I have to measure the time spent with the ordering.
Are you using linux as an OS? For a simple program like this I suggest you use time ./a.out
in the terminal, where a.out
is the executable of your program. This command prints 3 lines (explained briefly):
real
: Actual start time at end of execution; sys
: Time spent by the system kernel in the process of executing your program; user
: Time used in user-mode . This is the amount of time your computer spends in the process outside the kernel; You can calculate the runtime of functions using C ++ 11 with high precision using the library. <chrono>
. For example:
auto inicio = std::chrono::high_resolution_clock::now();
...SEU CÓDIGO AQUI...
auto resultado = std::chrono::high_resolution_clock::now() - inicio;
long long microseconds = std::chrono::duration_cast<std::chrono::microseconds>(resultado).count();
Since you can replace std::chrono::microseconds
(microseconds) with std::chrono::milliseconds
(milliseconds), std::chrono::seconds
(seconds) or even std::chrono::nanoseconds
(nanoseconds).