Monday, February 14, 2011

Pattern to measure the time of execution

It often happens that you need the way to measure the time of certain step execution in your scenarios or just your own scripts. What is the convenient way of doing this? The practice I use is to wrap the steps with ad-hoc class that is declared abstract and having the following structure:

This way will allow you to manage the measurement aspects without the necessity of all the code refactoring. Here is the example of how to use this approach:
Here it is presented how to measure the certain step's execution time. We should instantiate that abstract class right within the code to be measured so it will be wrapped with step() method implementation for each required part of code.
The provided example shows how I measured some files.