I wrote a program and now I want to calculate the total running time of my program from start to end.
How can I do this?
To calculate the running time, find the maximum number of nested loops that go through a significant portion of the input. Some algorithms use nested loops where the outer loop goes through an input n while the inner loop goes through a different input m. The time complexity in such cases is O(nm).
Run time is a phase of a computer program in which the program is run or executed on a computer system. Run time is part of the program life cycle, and it describes the time between when the program begins running within the memory until it is terminated or closed by the user or the operating system.
Using Instant. Instant class can be used to record event time-stamps in the application. It has now() method that obtains the current instant from the system clock. We can convert this instant to the total number of milliseconds using toEpochMilli() method. Please note that Instant.
Use System.nanoTime to get the current time.
long startTime = System.nanoTime(); .....your program.... long endTime = System.nanoTime(); long totalTime = endTime - startTime; System.out.println(totalTime);
The above code prints the running time of the program in nanoseconds.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With