于郑生 发表于 2013-8-16 15:56:21

[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:26

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]
查看完整版本: [Oracle interview]Give a simplest way to find out the time a method takes for execution without using any profiling tool?