KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > performance > standard > OptimizedInvocationTEST


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package test.performance.standard;
23
24 import junit.framework.TestCase;
25 import test.performance.PerformanceSUITE;
26 import test.performance.standard.support.Standard;
27
28 import javax.management.*;
29
30 import org.jboss.mx.server.ServerConstants;
31
32 /**
33  * Tests the performance of the byte code optimized invocation dispatcher.
34  *
35  * @author <a HREF="mailto:juha@jboss.org">Juha Lindfors</a>.
36  * @version $Revision: 37459 $
37  *
38  */

39 public class OptimizedInvocationTEST extends TestCase
40       implements ServerConstants
41 {
42
43    public OptimizedInvocationTEST(String JavaDoc s)
44    {
45       super(s);
46    }
47
48    public void testVoidInvocationWithDefaultDomain()
49    {
50       try
51       {
52          System.setProperty(OPTIMIZE_REFLECTED_DISPATCHER, "true");
53
54
55          System.out.println("\nSTANDARD (OPTIMIZED): void invocation with DefaultDomain");
56          System.out.println(PerformanceSUITE.ITERATION_COUNT + " Invocations, Repeat: x" + PerformanceSUITE.REPEAT_COUNT);
57          System.out.println("(this may take a while...)\n");
58
59          MBeanServer server = MBeanServerFactory.createMBeanServer();
60          ObjectName name = new ObjectName(":performanceTest=standard");
61          String JavaDoc method = "methodInvocation";
62          long start = 0, end = 0;
63          float avg = 0l;
64
65          server.registerMBean(new Standard(), name);
66
67          // drop the first batch (+1)
68
for (int testIterations = 0; testIterations < PerformanceSUITE.REPEAT_COUNT + 1; ++testIterations)
69          {
70             start = System.currentTimeMillis();
71             for (int invocationIterations = 0; invocationIterations < PerformanceSUITE.ITERATION_COUNT; ++invocationIterations)
72             {
73                server.invoke(name, method, null, null);
74             }
75             end = System.currentTimeMillis();
76
77             if (testIterations != 0)
78             {
79                long time = end - start;
80                System.out.print( time + " ");
81                avg += time;
82             }
83          }
84
85          System.out.println("\nAverage: " + (avg/PerformanceSUITE.REPEAT_COUNT));
86       }
87       catch (Throwable JavaDoc t)
88       {
89          t.printStackTrace();
90          fail("Unexpected error: " + t.toString());
91       }
92       finally
93       {
94          System.setProperty(OPTIMIZE_REFLECTED_DISPATCHER, "false");
95       }
96    }
97
98    public void testVoidInvocation()
99    {
100       try
101       {
102          System.setProperty(OPTIMIZE_REFLECTED_DISPATCHER, "true");
103          
104          
105          System.out.println("\nSTANDARD (OPTIMIZED): void invocation");
106          System.out.println(PerformanceSUITE.ITERATION_COUNT + " Invocations, Repeat: x" + PerformanceSUITE.REPEAT_COUNT);
107          System.out.println("(this may take a while...)\n");
108
109          MBeanServer server = MBeanServerFactory.createMBeanServer();
110          ObjectName name = new ObjectName("Domain:performanceTest=standard");
111          String JavaDoc method = "methodInvocation";
112          long start = 0, end = 0;
113          float avg = 0l;
114
115          server.registerMBean(new Standard(), name);
116
117          // drop the first batch (+1)
118
for (int testIterations = 0; testIterations < PerformanceSUITE.REPEAT_COUNT + 1; ++testIterations)
119          {
120             start = System.currentTimeMillis();
121             for (int invocationIterations = 0; invocationIterations < PerformanceSUITE.ITERATION_COUNT; ++invocationIterations)
122             {
123                server.invoke(name, method, null, null);
124             }
125             end = System.currentTimeMillis();
126
127             if (testIterations != 0)
128             {
129                long time = end - start;
130                System.out.print( time + " ");
131                avg += time;
132             }
133          }
134
135          System.out.println("\nAverage: " + (avg/PerformanceSUITE.REPEAT_COUNT));
136       }
137       catch (Throwable JavaDoc t)
138       {
139          t.printStackTrace();
140          fail("Unexpected error: " + t.toString());
141       }
142       finally
143       {
144          System.setProperty(OPTIMIZE_REFLECTED_DISPATCHER, "false");
145       }
146    }
147
148    public void testCounterInvocation()
149    {
150       try
151       {
152          System.setProperty(OPTIMIZE_REFLECTED_DISPATCHER, "true");
153
154
155          System.out.println("\nSTANDARD (OPTIMIZED): counter invocation");
156          System.out.println(PerformanceSUITE.ITERATION_COUNT + " Invocations, Repeat: x" + PerformanceSUITE.REPEAT_COUNT);
157          System.out.println("(this may take a while...)\n");
158
159          MBeanServer server = MBeanServerFactory.createMBeanServer();
160          ObjectName name = new ObjectName("Domain:performanceTest=standard");
161          Standard mbean = new Standard();
162          String JavaDoc method = "counter";
163          long start = 0, end = 0;
164          float avg = 0l;
165
166          server.registerMBean(mbean, name);
167
168          // drop the first batch (+1)
169
for (int testIterations = 0; testIterations < PerformanceSUITE.REPEAT_COUNT + 1; ++testIterations)
170          {
171             start = System.currentTimeMillis();
172             for (int invocationIterations = 0; invocationIterations < PerformanceSUITE.ITERATION_COUNT; ++invocationIterations)
173             {
174                server.invoke(name, method, null, null);
175             }
176             end = System.currentTimeMillis();
177
178             if (testIterations != 0)
179             {
180                long time = end - start;
181                System.out.print( time + " ");
182                avg += time;
183             }
184          }
185
186          System.out.println("\nAverage: " + (avg/PerformanceSUITE.REPEAT_COUNT));
187
188          assertTrue(mbean.getCount() == (PerformanceSUITE.REPEAT_COUNT + 1)*PerformanceSUITE.ITERATION_COUNT);
189       }
190       catch (Throwable JavaDoc t)
191       {
192          t.printStackTrace();
193          fail("Unexpected error: " + t.toString());
194       }
195       finally
196       {
197          System.setProperty(OPTIMIZE_REFLECTED_DISPATCHER, "false");
198       }
199    }
200
201
202    public void testMixedArgsInvocation()
203    {
204       try
205       {
206          System.setProperty(OPTIMIZE_REFLECTED_DISPATCHER, "true");
207          
208          System.out.println("\nSTANDARD (OPTIMIZED): mixed arguments invocation");
209          System.out.println(PerformanceSUITE.ITERATION_COUNT + " Invocations, Repeat: x" + PerformanceSUITE.REPEAT_COUNT);
210          System.out.println("(this may take a while...)\n");
211
212          MBeanServer server = MBeanServerFactory.createMBeanServer();
213          ObjectName name = new ObjectName("Domain:performanceTest=standard");
214          Standard mbean = new Standard();
215          
216          String JavaDoc method = "mixedArguments";
217          String JavaDoc[] signature = new String JavaDoc[] {
218                                  Integer JavaDoc.class.getName(),
219                                  int.class.getName(),
220                                  Object JavaDoc[][][].class.getName(),
221                                  Attribute.class.getName()
222                               };
223                               
224          Object JavaDoc[] args = new Object JavaDoc[] {
225                                  new Integer JavaDoc(1234),
226                                  new Integer JavaDoc(455617),
227                                  new Object JavaDoc[][][] {
228                                     {
229                                        { "1x1x1", "1x1x2", "1x1x3" },
230                                        { "1x2x1", "1x2x2", "1x2x3" },
231                                        { "1x3x1", "1x3x2", "1x3x3" }
232                                     },
233                                     
234                                     {
235                                        { "2x1x1", "2x1x2", "2x1x3" },
236                                        { "2x2x1", "2x2x2", "2x2x3" },
237                                        { "2x3x1", "2x3x2", "2x3x3" }
238                                     },
239                                     
240                                     {
241                                        { "3x1x1", "3x1x2", "3x1x3" },
242                                        { "3x2x1", "3x2x2", "3x2x3" },
243                                        { "3x3x1", "3x3x2", "3x3x3" }
244                                     }
245                                  },
246                                  new Attribute("attribute", "value")
247                               };
248                                     
249          long start = 0, end = 0;
250          float avg = 0l;
251
252          server.registerMBean(mbean, name);
253
254          // drop the first batch (+1)
255
for (int testIterations = 0; testIterations < PerformanceSUITE.REPEAT_COUNT + 1; ++testIterations)
256          {
257             start = System.currentTimeMillis();
258             for (int invocationIterations = 0; invocationIterations < PerformanceSUITE.ITERATION_COUNT; ++invocationIterations)
259             {
260                server.invoke(name, method, args, signature);
261             }
262             end = System.currentTimeMillis();
263
264             if (testIterations != 0)
265             {
266                long time = end - start;
267                System.out.print( time + " ");
268                avg += time;
269             }
270          }
271
272          System.out.println("\nAverage: " + (avg/PerformanceSUITE.REPEAT_COUNT));
273
274       }
275       catch (Throwable JavaDoc t)
276       {
277          t.printStackTrace();
278          fail("Unexpected error: " + t.toString());
279       }
280       finally
281       {
282          System.setProperty(OPTIMIZE_REFLECTED_DISPATCHER, "false");
283       }
284
285    }
286    
287 }
288
Popular Tags