Tool to Measure Java Software Performance

1

I would like to know if anyone knows of any tool to measure d esempenho de um algoritmo .

I'll give you an example:

I have two sorting algorithms, and I wanted to measure how much tempo , memória and etc ... each one spends

I've used Java Monitor do Eclipse but I'm not relying heavily on results.

    
asked by anonymous 07.06.2015 / 02:11

1 answer

0

Yes, there is a way, there is an API that I have designed to address this, using Aspect-Oriented Programming. I do not want to go into details about the paradigm here, but let's take care of it.

First Option - Green Aspect Utils This is my framework with Aspects, including Log with profiling level. If you want to use my Framework, go to this link:

link

Simply add the @LoggableObject annotation to your method as follows:

@LoggableObject(logMode={LoggableObject.LogModes.PROFILE})
    private int seuMetodo(String a, Integer b, String y, Object o, String c){
        //Conputacoes e execucao de seus algoritmos
        return 1;
    }

Note: In order to use my framework you will need the minimal Maven

When you run this program, you will see this information you want.

Second Option, just use a profiling tool such as JConsole, JProfile

The JConsole is in the folder C: \ Program Files (x86) \ Java \ jdk1.7.0_51 \ bin

Third Option - Write your own profiling code

What will be something in this template:

public static void seuMethod() {
    // sua logica
}
public static void main(String[] args) {
    // Memória total
    System.out.println("Memória total: "
            + Runtime.getRuntime().totalMemory());

    // Memória livre
    System.out.println("Memória livre: "
            + Runtime.getRuntime().freeMemory());

    // Tempo de inicio
    long initialTime = System.nanoTime();

    seuMethod();

    System.out.println("Tempo de execução total --> "
            + (System.nanoTime() - initialTime));

    System.out.println("Memória total: "
            + Runtime.getRuntime().totalMemory());

    // Memória livre
    System.out.println("Memória livre: "
            + Runtime.getRuntime().freeMemory());

}

Read the code comments, it should help you

Note the use of methods before and after the execution of your methods.

  • Runtime.getRuntime (). freeMemory ()
  • Runtime.getRuntime (). totalMemory ()
07.06.2015 / 02:28