March 2002
Intermediate to advanced
496 pages
8h 51m
English
Suppose that you want to let developers time how long a method takes to execute. Figure 24.1 shows a Command interface and a time() utility that times the execution of a command.

The code for time() captures the system time before and after executing the command and returns the difference:
public static long time(Command c)
{
long t1 = System.currentTimeMillis();
c.execute();
long t2 = System.currentTimeMillis();
return t2 - t1;
}
Suppose that you decide to test the time() method with an automated testing tool. ...
Read now
Unlock full access