How can I measure the execution time of my program locally?

execution-time
faq

#1

How can i measure the execution time of my program locally?


#2

Java

start = System.currentTimeMillis(); // Program Start

end = System.currentTimeMillis(); // Program End

System.out.println("

Time taken to copy in milliseconds: " +(end - start));


#3

In unix, if your output file is called out.txt, you can get the execution time with the command time ./out.txt. Otherwise, you could just use functions from your programming language which measure the time at the start and end, and print out the difference.


#4

If you use a newer compiler then you can use the following snippet

C++11 only

// Timing Code
#include <chrono>
typedef long long ll;

std::chrono::time_point<std::chrono::high_resolution_clock> start, end;
start = std::chrono::high_resolution_clock::now();
/*
Code goes here
*/
end = std::chrono::high_resolution_clock::now();
ll elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(end-start).count();
cout << "

Elapsed Time: " << elapsed_time << "ms
";


#5

This question has been asked and answered before. Please refer to this: http://discuss.codechef.com/questions/7129/time-taken-by-codes-to-run?page=1#7135


#6

admin, please, there is no way this would work !!!

time in Unix shows the execution time of following command

time [command]

so for example if test is executable compiled for example from test.cpp, than one can use

time test > test.out