R
R
Ruslan Ganzhuk2016-09-25 23:11:12
Java
Ruslan Ganzhuk, 2016-09-25 23:11:12

How to return the time of standard collection methods in java?

Whether prompt there is a method returning time operation of standard methods in a collection?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey Gornostaev, 2016-09-26
@sergey-gornostaev

long startTime = System.nanoTime();
someList.contains(someVar);
long endTime = System.nanoTime();
long duration = endTime - startTime;

A
aol-nnov, 2016-09-26
@aol-nnov

if the abbreviation AOP does not scare you, you can try. there are plenty of examples on the internet.
for example
, but under the hood it will be exactly the same as suggested by Sergey Gornostaev

P
protven, 2016-09-26
@protven

Why do you need to profile the standard methods of standard collections in java ? Have you run into them? I highly doubt it, in 99% of cases the network / database trip / reading and writing to disk slows down. If you need to "speed up" the standard Java library, you have chosen the wrong tool. Rewrite bottlenecks in C.
Here is a very useful squat to profile "your" methods. It is better to use some complete solution for this, for example based on this metrics.dropwizard.io/3.1.0/getting-started

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question