标题: [Oracle interview]Give a simplest way to find out the time a method takes for execution without using any profiling tool? [打印本页] 作者: 于郑生 时间: 2013-8-16 15:56 标题: [Oracle interview]Give a simplest way to find out the time a method takes for execution without using any profiling tool? 作者: 姜青林 时间: 2013-8-16 16:03
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.