J
J
Just_for_students2017-10-20 20:59:28
Java
Just_for_students, 2017-10-20 20:59:28

How to measure the execution time of a piece of code?

The essence of the question is, there is a package of sorting algorithms, each algorithm is implemented in a separate class, how to measure the sorting execution time? nanoTime() and currentTimeMillis() are somehow lost in this regard, nanoTime() smokes in threads, currentTimeMillis() accuracy is lame. Help, gentlemen. It is desirable to have your own solution methods from life experience, and not links to lectures and video reviews about timestamps.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wataru, 2017-10-20
@Just_for_students

There is only one approach - we run the same piece of code with the same input data many, many (thousand, million, 10 million) times. We measure time with something simple, like currentTimeMillis(). Then we divide by the number of launches.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question