Have you ever thought of how much processing time is taken to execute certain code or a method? It is good approach to check the execution time taken if you are calling an external api's or a web service for which you do not have the control.
Below is the code by which you can do it in a simple way in Java.
System.out.println("Calling service method...");
long t1 = System.currentTimeMillis();
//Below will be your complex code which you expect will take time and is critical
Object[] entity = service_port.getInfoByID(1103);
System.out.println("Time taken for Info service = " + ((System.currentTimeMillis() - t1) + " milli seconds");
The above code will print the time taken to execute the code in milliseconds. This will allow you to check if the complex code is taking much of the execution time and hence forth you can optimize your code and api's used to reduce the execution time. It is a very good idea to check the execution time if your application is going to run on real time which can affect the business.
No comments:
Post a Comment