java execution time
long start = System.currentTimeMillis();
class.method();
long time = System.currentTimeMillis() - start;
java execution time
long start = System.currentTimeMillis();
class.method();
long time = System.currentTimeMillis() - start;
How to measure the running time of a code section in Java?
import java.time.Duration;
import java.time.Instant;
public class RunningTime {
public static void main(String[] args) {
// Create a first time stamp
Instant start = Instant.now();
// Time-consuming code
for(int idx = 1; idx <= 1000_000_000; idx++) {
System.out.println(idx);
}
// Create a second time stamp
Instant end = Instant.now();
// Measure time elapsing between 2 time stamps
System.out.println("Running time in ms: " +
Duration.between(start, end));
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us