top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Give a simplest way to find the time a method takes for execution without using any profiling tool?

+2 votes
694 views
Give a simplest way to find the time a method takes for execution without using any profiling tool?
posted Sep 15, 2013 by Arvind Singh

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

Read the system time just before the method is invoked and immediately after method returns take the time difference,which 'll give you the time taken by a method for execution.
use this code.....

long start=System.currentTimeMillis();
method();
long end=System.currentTimeMillis();
System.out.println("Time taken for execution is"+(end-start));
answer Sep 15, 2013 by Vinay Shukla
...