el_shinito
Una forma de medir el tiempo de ejecución de un algoritmo, es tomar el tiempo inicial, luego ejecutar la tarea (en tu caso bubble sort) y luego tomar el tiempo final, haces una resta y puedes obtener aproximadamente el tiempo de ejecución de la tarea.
Puedes usar la función System.currentTimeMillis()
Respecto a escribir archivos, tambien es sencillo y hay varios ejemplos en el foro o en la red, date el tiempo para buscar.
Bueno te dejo un pequeño ejemplo, que mide el tiempo que demora en ordenar un vector de floats aleatorios (10000 posiciones).
Código JAVA:
Ver originalpackage org.deerme.examples;
/**
* This code is an example
* @author deerme.org
*/
public class MedirTiempo {
private float numbers[] = new float[10000];
public MedirTiempo()
{
// Llenamos Aleatoriamente el Vector (entre 0 y 100)
for(int i=0;i<numbers.length;i++)
{
numbers
[i
] = (float) Math.
random()*100; }
}
public void ordenarBubbleSort()
{
long time_init,time_total;
int i,j,countcicles=0;float aux;
// Medimos el tiempo
time_init
= System.
currentTimeMillis();
for (i = 0; i < numbers.length; i++)
{
for (j = 0; j < numbers.length - 1; j++)
{
if (numbers[j] > numbers[j+1])
{
aux = numbers[j];
numbers[j] = numbers[j+1];
numbers[j+1] = aux;
countcicles++;
}
}
}
time_total
= System.
currentTimeMillis() - time_init
; System.
out.
println("Nos hemos demorado " + time_total
+ " milisegundos en ordenar el vector a travéz de BubbleSort" );
}
public void ImprimirVector()
{
for(int i=0;i<numbers.length;i++)
{
System.
out.
println( numbers
[i
] ); }
}
public static void main
(String[] args
) { MedirTiempo mt = new MedirTiempo();
mt.ordenarBubbleSort();
}
}
Saludos