Demo entry 3534738

MediciĆ³n del tiempo en Java

   

Submitted by anonymous on Jan 10, 2016 at 19:53
Language: Java. Code size: 692 Bytes.

public class Timing {
	public static void main(String[] args) {
		int numpasses;
		numpasses = 1000;
		
		//Milliseconds
		long milli1 = System.currentTimeMillis(); 
		for (int i = 0; i < numpasses; i++) {
			System.out.println("hello world"); 
		}
		long milli2 = System.currentTimeMillis();
		
		//Nanoseconds
		long nano1 = System.nanoTime();
		for (int i = 0; i < numpasses; i++) {
			System.out.println("hello world"); 
		}
		long nano2 = System.nanoTime();

		System.out.println("Completed " + numpasses + " passes in " + (milli2 - milli1) + " milliseconds");
		System.out.println("Completed " + numpasses + " passes in " + (nano2 - nano1) + " nanoseconds"); 
	}
}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).