Archive

Posts Tagged ‘performance’

To create a new array or fill it? Java Array Performance

October 12, 2016 Leave a comment

Recently I needed to empty an array to use it later, and asked myself, what is the better option, to create a new one or fill it?
Maybe you have known this long ago, I didn’t. But now, we both know!


int freq[] = new int[256];
//This is better:
                Arrays.fill(freq,0);
//than:
                freq = new int[256];
Categories: Java, Mini-tips, Programación

Obtener el tiempo de lo que dura la ejecución de un método en Java

January 20, 2015 Leave a comment

		long ini = System.nanoTime();
		doYourStuffMethod();
		long fin = System.nanoTime();
		long duracion = TimeUnit.NANOSECONDS.toSeconds(fin - ini);
		System.out.println("Esa madre duró estos segundos:" + duracion);

Categories: Java, Mini-tips, snippets