How to find time taken by our code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

How to find time taken by our code?

some code output says time exceed

9th Apr 2017, 6:06 PM
Posi2
Posi2 - avatar
6 Answers
+ 9
In java, you can use System.nanoTime() to get the current time of execution. Then just convert the nanoseconds to regular seconds. You didn't ask for the language, soo :P.
9th Apr 2017, 6:19 PM
Rrestoring faith
Rrestoring faith - avatar
+ 9
C++: clock_t time = clock(); // Your code cout << (double) (clock() - time) / CLOCKS_PER_SEC; and don't forget #include <time.h> Java: Check out the main() function in this code. https://code.sololearn.com/c10BAhXfFGbP/?ref=app
10th Apr 2017, 1:47 AM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 4
language cpp
9th Apr 2017, 6:46 PM
Posi2
Posi2 - avatar
+ 4
use NPTEL video for time complexity
18th Apr 2017, 8:02 AM
Posi2
Posi2 - avatar
+ 3
generally we calculate time as function O(n) for loop O(n2) for two for loop O(n2) for tree. what is it? if anyone has list please give
10th Apr 2017, 11:41 AM
Posi2
Posi2 - avatar
+ 2
In c# you can make a stopwatch class, start it after user input and stop it at the end then call for elapsed time.
9th Apr 2017, 6:21 PM
Dextozz
Dextozz - avatar