Is it possible to create a method that times another method by reference in Java?
I’m thinking of something like:
int timeMethod(method myMethod) {
long start = time
run myMethod
long end = time
return end-start
}
You can wrap your method call in a
Runnableand time how long it takes theRunnableto run:Then you can time your method as follows: