1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package net.sf.ehcache;
18
19 import junit.framework.TestCase;
20 import org.apache.commons.logging.Log;
21 import org.apache.commons.logging.LogFactory;
22
23
24
25
26
27
28
29 public class StatusTest extends TestCase {
30 private static final Log LOG = LogFactory.getLog(StatusTest.class.getName());
31
32 private static int int1 = 1;
33 private int int2 = 2;
34 private Status status1 = Status.STATUS_ALIVE;
35
36
37
38
39
40
41 public void testEqualsPerformance() {
42 StopWatch stopWatch = new StopWatch();
43 stopWatch.getElapsedTime();
44
45
46
47 Status status2 = Status.STATUS_SHUTDOWN;
48
49 for (int i = 0; i < 10000; i++) {
50 status1.equals(status2);
51 }
52 stopWatch.getElapsedTime();
53 for (int i = 0; i < 10000; i++) {
54 status1.equals(status2);
55 }
56 long statusCompareTime = stopWatch.getElapsedTime();
57 LOG.info("Time to do equals(Status): " + statusCompareTime);
58 assertTrue("Status compare is greater than permitted time", statusCompareTime < 35);
59
60 }
61
62
63
64
65
66 public void testObjectEqualsPerformance() {
67 StopWatch stopWatch = new StopWatch();
68 stopWatch.getElapsedTime();
69
70 Object object = new Object();
71 for (int i = 0; i < 10000; i++) {
72 status1.equals(object);
73 }
74 stopWatch.getElapsedTime();
75 for (int i = 0; i < 10000; i++) {
76 status1.equals(object);
77 }
78 long objectCompareTime = stopWatch.getElapsedTime();
79 LOG.info("Time to do equals(Object): " + objectCompareTime);
80 assertTrue("Status compare is greater than permitted time", objectCompareTime < 25);
81
82
83 }
84
85
86
87
88
89 public void testIntEqualsPerformance() {
90 StopWatch stopWatch = new StopWatch();
91 stopWatch.getElapsedTime();
92
93 int2 = 12;
94 boolean result;
95 for (int i = 0; i < 10000; i++) {
96 result = int1 == int2;
97 }
98 stopWatch.getElapsedTime();
99 for (int i = 0; i < 10000; i++) {
100 result = int1 == int2;
101 }
102 long intCompareTime = stopWatch.getElapsedTime();
103 LOG.info("Time to do int == int: " + intCompareTime);
104 assertTrue("Status compare is greater than permitted time", intCompareTime < 10);
105
106
107 }
108
109
110
111
112 }