D
D
dskozin2016-03-24 22:54:38
Java
dskozin, 2016-03-24 22:54:38

How to evaluate code execution speed in Intellij Idea?

Colleagues, hello!
Tell me, if there is some built-in functionality in Intellij Idea to check how fast the code or section of code is executed?
I’m still learning only and I immediately want to understand which method of solving a particular problem will be more effective.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Kornachev, 2016-03-25
@dskozin

There are two system methods:

System.nanoTime(); //величина текущего времени в наносекундах
System.currentTimeMillis(); //величина текущего времени в милисекундах

You do it like this:
long startTime = System.currentTimeMillis();
        
        {
            //какой- то код, скорость работы которого нужно оценить
        }

//время затраченное на выполнение кода
long time = System.currentTimeMillis() - startTime;

which method to use depends on the operations to be evaluated. If the operation is fast and the measurements were taken in milliseconds, then the result may be zero, in which case measure in nanoseconds.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question