public class TestOpCounterAndTimer
1: //TestOpCounterAndTimer.java
2: public class TestOpCounterAndTimer
3: {
4: public static void main(String[] args)
5: {
6: OperationCounter counter = new OperationCounter();
7: Stopwatch timer = new Stopwatch();
8: int n = 200;
9: counter.setNameOfOther("Additions");
10: timer.start();
11: int sum = 0;
12: counter.incrementAssignments();
13: timer.delay();
14: for (int i=1; i<=n; i++)
15: {
16: sum += i;
17: counter.incrementOther();
18: counter.incrementAssignments();
19: timer.delay(2);
20: }
21: timer.stop();
22: counter.display();
23: System.out.println("time = " + timer.getSeconds());
24: Utils.pause();
25: n = 20;
26: timer.start();
27: counter.reset();
28: counter.setNameOfOther("Additions");
29: sum = 0;
30: counter.incrementAssignments();
31: timer.delay();
32: for (int i=1; i<=n; i++)
33: {
34: for (int j=1; j<=n; j++)
35: {
36: sum += i;
37: counter.incrementOther();
38: counter.incrementAssignments();
39: timer.delay(2);
40: }
41: }
42: timer.stop();
43: counter.display();
44: System.out.println("time = " + timer.getSeconds());
45: Utils.pause();
46: }
47: }