[Oracle interview]Give a simplest way to find out the time a method takes for execution without using any profiling tool?
Read the systemtime just before the method is invoked and immediately after method returns.Take the time difference, which will give you the time taken by a method forexecution.To put it in code...long start = System.currentTimeMillis ();method ();long end = System.currentTimeMillis ();System.out.println ("Time taken forexecution is " + (end - start));Remember that if the time taken for execution istoo small, it might show that it is taking zero milliseconds for execution. Tryit on a method which is big enough, in the sense the one which is doingconsiderable amout of processing.
页:
[1]