Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

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));
	}
}
Comment

PREVIOUS NEXT
Code Example
Java :: java check ipv6 with regex 
Java :: remove last character from string 
Java :: internet access android manifest 
Java :: foreground java jframe 
Java :: prendere valore da tastiera java 
Java :: java string to long 
Java :: bukkit runnable 
Java :: init cap java 
Java :: padding a string with 0 in java 
Java :: java split string into list 
Java :: spigot get commandmap 
Java :: check if string contains numbers 
Java :: force fullscreen jframe 
Java :: java jtextfield text bold 
Java :: finally block does not complete normallyJava(536871096) 
Java :: leap year program in java 
Java :: bit hacks java 
Java :: java mouselistener get coordinates 
Java :: vector inline java 
Java :: java number padding zeros 
Java :: android how to start a new activity on button click 
Java :: method to check parameters in java 
Java :: android studio print console 
Java :: change color of text in textview android 
Java :: java new arraylist of n zeros 
Java :: jlabel on the center of a jpanel 
Java :: Traversing a double dimensional array 
Java :: android view to bitmap 
Java :: set to list java 
Java :: enter key java 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =