You are not logged in. Please login at www.codechef.com to post your questions!

×

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

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

asked 10 Apr '13, 15:29

rudreshwar's gravatar image

1★rudreshwar
457192531
accept rate: 50%


Java

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

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

System.out.println("nnTime taken to copy in milliseconds: " +(end - start));

link

answered 10 Apr '13, 15:50

aayush_code's gravatar image

2★aayush_code
40359
accept rate: 0%

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 << "\nElapsed Time: " << elapsed_time << "ms\n";
link

answered 10 Apr '13, 19:19

ishanbhatnagar's gravatar image

5★ishanbhatnagar
8502614
accept rate: 21%

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

link

answered 11 Apr '13, 03:17

kullalok's gravatar image

2★kullalok
1.5k112236
accept rate: 14%

-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.

link

answered 10 Apr '13, 15:53

admin's gravatar image

0★admin ♦♦
19.6k349497539
accept rate: 35%

2

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
(10 Apr '13, 20:32) betlista ♦♦3★
toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×206
×74

question asked: 10 Apr '13, 15:29

question was seen: 10,327 times

last updated: 07 May '16, 07:28