Tool to Measure Java Software Performance

Asked

Viewed 878 times

1

I wonder if anyone knows any tools to measure theesempenho de um algoritmo.

Let me give you an example:

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

I’ve been using the Java Monitor do Eclipse but I’m not relying too much on the results.

1 answer

0


Yes, there is a way, yes, there is an API that I designed to meet that, using Aspect-Oriented Programming. I don’t want to go into details about the paradigm here, but we will meet your need.

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

https://github.com/FilipeGMiranda/Green-Aspect-Utils

Just add the @Loggableobject logo annotation to your method in this way:

@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: To use my framework you will need the least of Maven

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

Second Option, just use a Profiling tool such as Jconsole, Jprofile

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

Third Option - Write your own Profiling code

That 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, should help you

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

  • Runtime.getRuntime(). freeMemory()
  • Runtime.getRuntime(). totalMemory()
  • Grateful for the Help Felipe!

  • That’s why we’re here, let me know if everything works normally. And follow me on Github, to track the evolution of the API

Browser other questions tagged

You are not signed in. Login or sign up in order to post.