How to make a Java algorithm that can measure the runtime of the Heap Sort sort algorithm?

0

I started my algorithm in this way so that it is able to measure its execution time, but I'm not sure if it's right, like continuing with an example:

package heapsort;

public class Heapsort {


    public static void main(String[] args) {

        int quantidade = 1000;
        int[] vetor = new int[quantidade];
        int tamanho;

        for(int i = 0; i < vetor.length; i++){
            vetor[i] = (int) (Math.random()*quantidade);
        }

        long tempoInicial = System.currentTimeMillis();


    }

}
    
asked by anonymous 04.07.2018 / 16:05

1 answer

0

You must first save the initial currentTimeMillis () and then compare with the end.

long tempoInicial = System.currentTimeMillis();

// execução do método

System.out.println("O método foi executado em " + System.currentTimeMillis() - tempoInicial);

System.currentTimeMillis () is a function that returns the difference, measured in milliseconds, between the current time and midnight of January 1, 1970 UTC (coordinated universal time).

    
04.07.2018 / 18:51