KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > avalon > excalibur > pool > test > PoolProfile


1 /*
2  * Copyright The Apache Software Foundation. All rights reserved.
3  *
4  * This software is published under the terms of the Apache Software License
5  * version 1.1, a copy of which has been included with this distribution in
6  * the LICENSE.txt file.
7  */

8 package org.apache.avalon.excalibur.pool.test;
9
10 import org.apache.avalon.excalibur.pool.SingleThreadedPool;
11 import org.apache.avalon.excalibur.pool.Poolable;
12 import org.apache.avalon.excalibur.pool.DefaultPool;
13 import org.apache.avalon.excalibur.pool.Pool;
14 import org.apache.avalon.excalibur.pool.SoftResourceLimitingPool;
15 import junit.framework.*;
16
17 /**
18  * This is used to profile the Pool implementation.
19  *
20  * @author <a HREF="mailto:peter@apache.org">Peter Donald</a>
21  */

22 public final class PoolProfile
23     extends TestCase
24 {
25     org.apache.log.Logger logger = org.apache.log.Hierarchy.getDefaultHierarchy().getLoggerFor("test");
26
27     public PoolProfile(String JavaDoc name)
28     {
29         super(name);
30
31         logger.setPriority(org.apache.log.Priority.INFO);
32     }
33
34     public static class A
35         implements Poolable
36     {
37         int a;
38         int b;
39         int c;
40         float x;
41         float y;
42         float z;
43     }
44
45     public static class B
46         implements Poolable
47     {
48         int a;
49         int b;
50         int c;
51         float x;
52         float y;
53         float z;
54         Object JavaDoc[] o1 = new Object JavaDoc[10];
55         Object JavaDoc[] o2 = new Object JavaDoc[10];
56         Object JavaDoc[] o3 = new Object JavaDoc[10];
57
58         public void recycle()
59         {
60             o1 = o2 = o3 = null;
61         }
62     }
63
64     public static class C
65         implements Poolable
66     {
67         int a;
68         int b;
69         int c;
70         float x;
71         float y;
72         float z;
73         Object JavaDoc[] o1 = new Object JavaDoc[100];
74         Object JavaDoc[] o2 = new Object JavaDoc[100];
75         Object JavaDoc[] o3 = new Object JavaDoc[100];
76         Object JavaDoc[] o4 = new Object JavaDoc[100];
77         Object JavaDoc[] o5 = new Object JavaDoc[100];
78         Object JavaDoc[] o6 = new Object JavaDoc[100];
79
80         public void recycle()
81         {
82             o1 = o2 = o3 = o4 = o5 = o6 = null;
83         }
84     }
85
86     protected static final int TEST_SIZE = 1000000;
87
88     public void testSmallObjects()
89         throws Exception JavaDoc
90     {
91         logger.info("SMALL Sized Objects");
92
93         final SingleThreadedPool pool1 = new SingleThreadedPool( A.class, 5, 10 );
94         final long pool1Start = System.currentTimeMillis();
95         final int pool1Factor = 1;
96         final int pool1Loops = TEST_SIZE / pool1Factor;
97         for( int i = 0; i < TEST_SIZE; i++ )
98         {
99             final Poolable a1 = pool1.get();
100             pool1.put(a1);
101         }
102         final long pool1End = System.currentTimeMillis();
103         final long pool1Duration = pool1End - pool1Start;
104
105         System.gc();
106         System.gc();
107         Thread.currentThread().sleep(2);
108
109         if (logger.isDebugEnabled()) logger.debug("FreeMem post 1: " + Runtime.getRuntime().freeMemory() );
110
111         final SingleThreadedPool pool2 = new SingleThreadedPool( A.class, 5, 10 );
112         final long pool2Start = System.currentTimeMillis();
113         final int pool2Factor = 10;
114         final int pool2Loops = TEST_SIZE / pool2Factor;
115         for( int i = 0; i < pool2Loops; i++ )
116         {
117             final Poolable a1 = pool2.get();
118             final Poolable a2 = pool2.get();
119             final Poolable a3 = pool2.get();
120             final Poolable a4 = pool2.get();
121             final Poolable a5 = pool2.get();
122             final Poolable a6 = pool2.get();
123             final Poolable a7 = pool2.get();
124             final Poolable a8 = pool2.get();
125             final Poolable a9 = pool2.get();
126             final Poolable a0 = pool2.get();
127             pool2.put(a1);
128             pool2.put(a2);
129             pool2.put(a3);
130             pool2.put(a4);
131             pool2.put(a5);
132             pool2.put(a6);
133             pool2.put(a7);
134             pool2.put(a8);
135             pool2.put(a9);
136             pool2.put(a0);
137         }
138         final long pool2End = System.currentTimeMillis();
139         final long pool2Duration = pool2End - pool2Start;
140
141         System.gc();
142         System.gc();
143         Thread.currentThread().sleep(2);
144
145         if (logger.isDebugEnabled()) logger.debug("FreeMem post 2: " + Runtime.getRuntime().freeMemory() );
146
147         final SingleThreadedPool pool3 = new SingleThreadedPool( A.class, 5, 10 );
148         final long pool3Start = System.currentTimeMillis();
149         final int pool3Factor = 15;
150         final int pool3Loops = TEST_SIZE / pool3Factor;
151         for( int i = 0; i < pool3Loops; i++ )
152         {
153             final Poolable a1 = pool3.get();
154             final Poolable a2 = pool3.get();
155             final Poolable a3 = pool3.get();
156             final Poolable a4 = pool3.get();
157             final Poolable a5 = pool3.get();
158             final Poolable a6 = pool3.get();
159             final Poolable a7 = pool3.get();
160             final Poolable a8 = pool3.get();
161             final Poolable a9 = pool3.get();
162             final Poolable a10 = pool3.get();
163             final Poolable a11 = pool3.get();
164             final Poolable a12 = pool3.get();
165             final Poolable a13 = pool3.get();
166             final Poolable a14 = pool3.get();
167             final Poolable a15 = pool3.get();
168             pool3.put(a1);
169             pool3.put(a2);
170             pool3.put(a3);
171             pool3.put(a4);
172             pool3.put(a5);
173             pool3.put(a6);
174             pool3.put(a7);
175             pool3.put(a8);
176             pool3.put(a9);
177             pool3.put(a10);
178             pool3.put(a11);
179             pool3.put(a12);
180             pool3.put(a13);
181             pool3.put(a14);
182             pool3.put(a15);
183         }
184         final long pool3End = System.currentTimeMillis();
185         final long pool3Duration = pool3End - pool3Start;
186
187         System.gc();
188         System.gc();
189         Thread.currentThread().sleep(2);
190
191         if (logger.isDebugEnabled()) logger.debug("FreeMem post 3: " + Runtime.getRuntime().freeMemory() );
192
193         final SingleThreadedPool pool4 = new SingleThreadedPool( A.class, 5, 10 );
194         final long pool4Start = System.currentTimeMillis();
195         final int pool4Factor = 20;
196         final int pool4Loops = TEST_SIZE / pool4Factor;
197         for( int i = 0; i < pool4Loops; i++ )
198         {
199             final Poolable a1 = pool4.get();
200             final Poolable a2 = pool4.get();
201             final Poolable a3 = pool4.get();
202             final Poolable a4 = pool4.get();
203             final Poolable a5 = pool4.get();
204             final Poolable a6 = pool4.get();
205             final Poolable a7 = pool4.get();
206             final Poolable a8 = pool4.get();
207             final Poolable a9 = pool4.get();
208             final Poolable a10 = pool4.get();
209             final Poolable a11 = pool4.get();
210             final Poolable a12 = pool4.get();
211             final Poolable a13 = pool4.get();
212             final Poolable a14 = pool4.get();
213             final Poolable a15 = pool4.get();
214             final Poolable a16 = pool4.get();
215             final Poolable a17 = pool4.get();
216             final Poolable a18 = pool4.get();
217             final Poolable a19 = pool4.get();
218             final Poolable a20 = pool4.get();
219             pool4.put(a1);
220             pool4.put(a2);
221             pool4.put(a3);
222             pool4.put(a4);
223             pool4.put(a5);
224             pool4.put(a6);
225             pool4.put(a7);
226             pool4.put(a8);
227             pool4.put(a9);
228             pool4.put(a10);
229             pool4.put(a11);
230             pool4.put(a12);
231             pool4.put(a13);
232             pool4.put(a14);
233             pool4.put(a15);
234             pool4.put(a16);
235             pool4.put(a17);
236             pool4.put(a18);
237             pool4.put(a19);
238             pool4.put(a20);
239         }
240         final long pool4End = System.currentTimeMillis();
241         final long pool4Duration = pool4End - pool4Start;
242
243         if (logger.isDebugEnabled()) logger.debug("FreeMem post 4: " + Runtime.getRuntime().freeMemory() );
244
245         final long createStart = System.currentTimeMillis();
246         for( int i = 0; i < TEST_SIZE; i++ )
247         {
248             final Poolable a1 = new C();
249         }
250         final long createEnd = System.currentTimeMillis();
251         final long createDuration = createEnd - createStart;
252
253         if (logger.isDebugEnabled()) logger.debug("FreeMem post create: " + Runtime.getRuntime().freeMemory() );
254
255         final double pool1Efficiency = (double)createDuration/(double)pool1Duration * 100.0;
256         final double pool2Efficiency = (double)createDuration/(double)pool2Duration * 100.0;
257         final double pool3Efficiency = (double)createDuration/(double)pool3Duration * 100.0;
258         final double pool4Efficiency = (double)createDuration/(double)pool4Duration * 100.0;
259
260         if (logger.isDebugEnabled()) logger.debug("Pool Efficiency for 100% hits: " + pool1Efficiency + "% ");
261         if (logger.isInfoEnabled()) logger.info("Time Saved for 100% hits: " + (createDuration - pool1Duration) + "ms ");
262
263         if (logger.isDebugEnabled()) logger.debug("Pool Efficiency for 100% hits and saturated: " + pool2Efficiency + "% ");
264         if (logger.isInfoEnabled()) logger.info("Time Saved for 100% hits: " + (createDuration - pool2Duration) + "ms ");
265
266         if (logger.isDebugEnabled()) logger.debug("Pool Efficiency for 60% hits: " + pool3Efficiency + "% ");
267         if (logger.isInfoEnabled()) logger.info("Time Saved for 60% hits: " + (createDuration - pool3Duration) + "ms ");
268
269         if (logger.isDebugEnabled()) logger.debug("Pool Efficiency for 50% hits: " + pool4Efficiency + "% ");
270         if (logger.isInfoEnabled()) logger.info("Time Saved for 50% hits: " + (createDuration - pool4Duration) + "ms ");
271     }
272
273     public void testMediumObjects()
274         throws Exception JavaDoc
275     {
276         logger.info("MEDIUM Sized Objects");
277
278         System.gc();
279         System.gc();
280         Thread.currentThread().sleep(2);
281
282         final SingleThreadedPool pool1 = new SingleThreadedPool( B.class, 5, 10 );
283         final long pool1Start = System.currentTimeMillis();
284         final int pool1Factor = 1;
285         final int pool1Loops = TEST_SIZE / pool1Factor;
286
287         for( int i = 0; i < TEST_SIZE; i++ )
288         {
289             final Poolable a1 = pool1.get();
290             pool1.put(a1);
291         }
292         final long pool1End = System.currentTimeMillis();
293         final long pool1Duration = pool1End - pool1Start;
294
295         System.gc();
296         System.gc();
297         Thread.currentThread().sleep(2);
298
299         if (logger.isDebugEnabled()) logger.debug("FreeMem post 1: " + Runtime.getRuntime().freeMemory() );
300
301         final SingleThreadedPool pool2 = new SingleThreadedPool( B.class, 5, 10 );
302         final long pool2Start = System.currentTimeMillis();
303         final int pool2Factor = 10;
304         final int pool2Loops = TEST_SIZE / pool2Factor;
305
306         for( int i = 0; i < pool2Loops; i++ )
307         {
308             final Poolable a1 = pool2.get();
309             final Poolable a2 = pool2.get();
310             final Poolable a3 = pool2.get();
311             final Poolable a4 = pool2.get();
312             final Poolable a5 = pool2.get();
313             final Poolable a6 = pool2.get();
314             final Poolable a7 = pool2.get();
315             final Poolable a8 = pool2.get();
316             final Poolable a9 = pool2.get();
317             final Poolable a10 = pool2.get();
318             pool2.put(a1);
319             pool2.put(a2);
320             pool2.put(a3);
321             pool2.put(a4);
322             pool2.put(a5);
323             pool2.put(a6);
324             pool2.put(a7);
325             pool2.put(a8);
326             pool2.put(a9);
327             pool2.put(a10);
328         }
329         final long pool2End = System.currentTimeMillis();
330         final long pool2Duration = pool2End - pool2Start;
331
332         System.gc();
333         System.gc();
334         Thread.currentThread().sleep(2);
335
336         if (logger.isDebugEnabled()) logger.debug("FreeMem post 2: " + Runtime.getRuntime().freeMemory() );
337
338         final SingleThreadedPool pool3 = new SingleThreadedPool( B.class, 5, 10 );
339         final long pool3Start = System.currentTimeMillis();
340         final int pool3Factor = 15;
341         final int pool3Loops = TEST_SIZE / pool3Factor;
342
343         for( int i = 0; i < pool3Loops; i++ )
344         {
345             final Poolable a1 = pool3.get();
346             final Poolable a2 = pool3.get();
347             final Poolable a3 = pool3.get();
348             final Poolable a4 = pool3.get();
349             final Poolable a5 = pool3.get();
350             final Poolable a6 = pool3.get();
351             final Poolable a7 = pool3.get();
352             final Poolable a8 = pool3.get();
353             final Poolable a9 = pool3.get();
354             final Poolable a10 = pool3.get();
355             final Poolable a11 = pool3.get();
356             final Poolable a12 = pool3.get();
357             final Poolable a13 = pool3.get();
358             final Poolable a14 = pool3.get();
359             final Poolable a15 = pool3.get();
360             pool3.put(a1);
361             pool3.put(a2);
362             pool3.put(a3);
363             pool3.put(a4);
364             pool3.put(a5);
365             pool3.put(a6);
366             pool3.put(a7);
367             pool3.put(a8);
368             pool3.put(a9);
369             pool3.put(a10);
370             pool3.put(a11);
371             pool3.put(a12);
372             pool3.put(a13);
373             pool3.put(a14);
374             pool3.put(a15);
375         }
376         final long pool3End = System.currentTimeMillis();
377         final long pool3Duration = pool3End - pool3Start;
378
379         System.gc();
380         System.gc();
381         Thread.currentThread().sleep(2);
382
383         if (logger.isDebugEnabled()) logger.debug("FreeMem post 3: " + Runtime.getRuntime().freeMemory() );
384
385         final SingleThreadedPool pool4 = new SingleThreadedPool( B.class, 5, 10 );
386         final long pool4Start = System.currentTimeMillis();
387         final int pool4Factor = 20;
388         final int pool4Loops = TEST_SIZE / pool4Factor;
389
390         for( int i = 0; i < pool4Loops; i++ )
391         {
392             final Poolable a1 = pool4.get();
393             final Poolable a2 = pool4.get();
394             final Poolable a3 = pool4.get();
395             final Poolable a4 = pool4.get();
396             final Poolable a5 = pool4.get();
397             final Poolable a6 = pool4.get();
398             final Poolable a7 = pool4.get();
399             final Poolable a8 = pool4.get();
400             final Poolable a9 = pool4.get();
401             final Poolable a10 = pool4.get();
402             final Poolable a11 = pool4.get();
403             final Poolable a12 = pool4.get();
404             final Poolable a13 = pool4.get();
405             final Poolable a14 = pool4.get();
406             final Poolable a15 = pool4.get();
407             final Poolable a16 = pool4.get();
408             final Poolable a17 = pool4.get();
409             final Poolable a18 = pool4.get();
410             final Poolable a19 = pool4.get();
411             final Poolable a20 = pool4.get();
412             pool4.put(a1);
413             pool4.put(a2);
414             pool4.put(a3);
415             pool4.put(a4);
416             pool4.put(a5);
417             pool4.put(a6);
418             pool4.put(a7);
419             pool4.put(a8);
420             pool4.put(a9);
421             pool4.put(a10);
422             pool4.put(a11);
423             pool4.put(a12);
424             pool4.put(a13);
425             pool4.put(a14);
426             pool4.put(a15);
427             pool4.put(a16);
428             pool4.put(a17);
429             pool4.put(a18);
430             pool4.put(a19);
431             pool4.put(a20);
432         }
433         final long pool4End = System.currentTimeMillis();
434         final long pool4Duration = pool4End - pool4Start;
435
436         if (logger.isDebugEnabled()) logger.debug("FreeMem post 4: " + Runtime.getRuntime().freeMemory() );
437
438         final long createStart = System.currentTimeMillis();
439         for( int i = 0; i < TEST_SIZE; i++ )
440         {
441             final Poolable a1 = new C();
442         }
443         final long createEnd = System.currentTimeMillis();
444         final long createDuration = createEnd - createStart;
445
446         if (logger.isDebugEnabled()) logger.debug("Create Duration: " + createDuration + "ms ");
447         if (logger.isDebugEnabled()) logger.debug("FreeMem post create: " + Runtime.getRuntime().freeMemory() );
448
449         final double pool1Efficiency = (double)createDuration/(double)pool1Duration * 100.0;
450         final double pool2Efficiency = (double)createDuration/(double)pool2Duration * 100.0;
451         final double pool3Efficiency = (double)createDuration/(double)pool3Duration * 100.0;
452         final double pool4Efficiency = (double)createDuration/(double)pool4Duration * 100.0;
453
454         if (logger.isDebugEnabled()) logger.debug("Pool Efficiency for 100% hits: " + pool1Efficiency + "% ");
455         if (logger.isInfoEnabled()) logger.info("Time Saved for 100% hits: " + (createDuration - pool1Duration) + "ms ");
456
457         if (logger.isDebugEnabled()) logger.debug("Pool Efficiency for 100% hits and saturated: " + pool2Efficiency + "% ");
458         if (logger.isInfoEnabled()) logger.info("Time Saved for 100% hits: " + (createDuration - pool2Duration) + "ms ");
459
460         if (logger.isDebugEnabled()) logger.debug("Pool Efficiency for 60% hits: " + pool3Efficiency + "% ");
461         if (logger.isInfoEnabled()) logger.info("Time Saved for 60% hits: " + (createDuration - pool3Duration) + "ms ");
462
463         if (logger.isDebugEnabled()) logger.debug("Pool Efficiency for 50% hits: " + pool4Efficiency + "% ");
464         if (logger.isInfoEnabled()) logger.info("Time Saved for 50% hits: " + (createDuration - pool4Duration) + "ms ");
465     }
466
467     public void testLargeObjects()
468         throws Exception JavaDoc
469     {
470         logger.info("LARGE Sized Objects");
471
472         System.gc();
473         System.gc();
474         Thread.currentThread().sleep(2);
475
476         final SingleThreadedPool pool1 = new SingleThreadedPool( C.class, 5, 10 );
477         final long pool1Start = System.currentTimeMillis();
478         final int pool1Factor = 1;
479         final int pool1Loops = TEST_SIZE / pool1Factor;
480         for( int i = 0; i < TEST_SIZE; i++ )
481         {
482             final Poolable a1 = pool1.get();
483             pool1.put(a1);
484         }
485         final long pool1End = System.currentTimeMillis();
486         final long pool1Duration = pool1End - pool1Start;
487
488         System.gc();
489         System.gc();
490         Thread.currentThread().sleep(2);
491
492         if (logger.isDebugEnabled()) logger.debug("FreeMem post 1: " + Runtime.getRuntime().freeMemory() );
493
494         final SingleThreadedPool pool2 = new SingleThreadedPool( C.class, 5, 10 );
495         final long pool2Start = System.currentTimeMillis();
496         final int pool2Factor = 10;
497         final int pool2Loops = TEST_SIZE / pool2Factor;
498         for( int i = 0; i < pool2Loops; i++ )
499         {
500             final Poolable a1 = pool2.get();
501             final Poolable a2 = pool2.get();
502             final Poolable a3 = pool2.get();
503             final Poolable a4 = pool2.get();
504             final Poolable a5 = pool2.get();
505             final Poolable a6 = pool2.get();
506             final Poolable a7 = pool2.get();
507             final Poolable a8 = pool2.get();
508             final Poolable a9 = pool2.get();
509             final Poolable a10 = pool2.get();
510             pool2.put(a1);
511             pool2.put(a2);
512             pool2.put(a3);
513             pool2.put(a4);
514             pool2.put(a5);
515             pool2.put(a6);
516             pool2.put(a7);
517             pool2.put(a8);
518             pool2.put(a9);
519             pool2.put(a10);
520         }
521         final long pool2End = System.currentTimeMillis();
522         final long pool2Duration = pool2End - pool2Start;
523
524         System.gc();
525         System.gc();
526         Thread.currentThread().sleep(2);
527
528         if (logger.isDebugEnabled()) logger.debug("FreeMem post 2: " + Runtime.getRuntime().freeMemory() );
529
530         final SingleThreadedPool pool3 = new SingleThreadedPool( C.class, 5, 10 );
531         final long pool3Start = System.currentTimeMillis();
532         final int pool3Factor = 15;
533         final int pool3Loops = TEST_SIZE / pool3Factor;
534         for( int i = 0; i < pool3Loops; i++ )
535         {
536             final Poolable a1 = pool3.get();
537             final Poolable a2 = pool3.get();
538             final Poolable a3 = pool3.get();
539             final Poolable a4 = pool3.get();
540             final Poolable a5 = pool3.get();
541             final Poolable a6 = pool3.get();
542             final Poolable a7 = pool3.get();
543             final Poolable a8 = pool3.get();
544             final Poolable a9 = pool3.get();
545             final Poolable a10 = pool3.get();
546             final Poolable a11 = pool3.get();
547             final Poolable a12 = pool3.get();
548             final Poolable a13 = pool3.get();
549             final Poolable a14 = pool3.get();
550             final Poolable a15 = pool3.get();
551             pool3.put(a1);
552             pool3.put(a2);
553             pool3.put(a3);
554             pool3.put(a4);
555             pool3.put(a5);
556             pool3.put(a6);
557             pool3.put(a7);
558             pool3.put(a8);
559             pool3.put(a9);
560             pool3.put(a10);
561             pool3.put(a11);
562             pool3.put(a12);
563             pool3.put(a13);
564             pool3.put(a14);
565             pool3.put(a15);
566         }
567         final long pool3End = System.currentTimeMillis();
568         final long pool3Duration = pool3End - pool3Start;
569
570         System.gc();
571         System.gc();
572         Thread.currentThread().sleep(2);
573
574         if (logger.isDebugEnabled()) logger.debug("FreeMem post 3: " + Runtime.getRuntime().freeMemory() );
575
576         final SingleThreadedPool pool4 = new SingleThreadedPool( C.class, 5, 10 );
577         final long pool4Start = System.currentTimeMillis();
578         final int pool4Factor = 20;
579         final int pool4Loops = TEST_SIZE / pool4Factor;
580
581         for( int i = 0; i < pool4Loops; i++ )
582         {
583             final Poolable a1 = pool4.get();
584             final Poolable a2 = pool4.get();
585             final Poolable a3 = pool4.get();
586             final Poolable a4 = pool4.get();
587             final Poolable a5 = pool4.get();
588             final Poolable a6 = pool4.get();
589             final Poolable a7 = pool4.get();
590             final Poolable a8 = pool4.get();
591             final Poolable a9 = pool4.get();
592             final Poolable a10 = pool4.get();
593             final Poolable a11 = pool4.get();
594             final Poolable a12 = pool4.get();
595             final Poolable a13 = pool4.get();
596             final Poolable a14 = pool4.get();
597             final Poolable a15 = pool4.get();
598             final Poolable a16 = pool4.get();
599             final Poolable a17 = pool4.get();
600             final Poolable a18 = pool4.get();
601             final Poolable a19 = pool4.get();
602             final Poolable a20 = pool4.get();
603             pool4.put(a1);
604             pool4.put(a2);
605             pool4.put(a3);
606             pool4.put(a4);
607             pool4.put(a5);
608             pool4.put(a6);
609             pool4.put(a7);
610             pool4.put(a8);
611             pool4.put(a9);
612             pool4.put(a10);
613             pool4.put(a11);
614             pool4.put(a12);
615             pool4.put(a13);
616             pool4.put(a14);
617             pool4.put(a15);
618             pool4.put(a16);
619             pool4.put(a17);
620             pool4.put(a18);
621             pool4.put(a19);
622             pool4.put(a20);
623         }
624         final long pool4End = System.currentTimeMillis();
625         final long pool4Duration = pool4End - pool4Start;
626
627         if (logger.isDebugEnabled()) logger.debug("FreeMem post 4: " + Runtime.getRuntime().freeMemory() );
628
629         final long createStart = System.currentTimeMillis();
630         for( int i = 0; i < TEST_SIZE; i++ )
631         {
632             final Poolable a1 = new C();
633         }
634         final long createEnd = System.currentTimeMillis();
635         final long createDuration = createEnd - createStart;
636
637         if (logger.isDebugEnabled()) logger.debug("FreeMem post create: " + Runtime.getRuntime().freeMemory() );
638
639         final double pool1Efficiency = (double)createDuration/(double)pool1Duration * 100.0;
640         final double pool2Efficiency = (double)createDuration/(double)pool2Duration * 100.0;
641         final double pool3Efficiency = (double)createDuration/(double)pool3Duration * 100.0;
642         final double pool4Efficiency = (double)createDuration/(double)pool4Duration * 100.0;
643
644         if (logger.isDebugEnabled()) logger.debug("Pool Efficiency for 100% hits: " + pool1Efficiency + "% ");
645         if (logger.isInfoEnabled()) logger.info("Time Saved for 100% hits: " + (createDuration - pool1Duration) + "ms ");
646
647         if (logger.isDebugEnabled()) logger.debug("Pool Efficiency for 100% hits and saturated: " + pool2Efficiency + "% ");
648         if (logger.isInfoEnabled()) logger.info("Time Saved for 100% hits: " + (createDuration - pool2Duration) + "ms ");
649
650         if (logger.isDebugEnabled()) logger.debug("Pool Efficiency for 60% hits: " + pool3Efficiency + "% ");
651         if (logger.isInfoEnabled()) logger.info("Time Saved for 60% hits: " + (createDuration - pool3Duration) + "ms ");
652
653         if (logger.isDebugEnabled()) logger.debug("Pool Efficiency for 50% hits: " + pool4Efficiency + "% ");
654         if (logger.isInfoEnabled()) logger.info("Time Saved for 50% hits: " + (createDuration - pool4Duration) + "ms ");
655     }
656
657
658     public void testThreadedSmallObjects()
659         throws Exception JavaDoc
660     {
661         logger.info("SMALL Sized Objects with thread safe pools");
662
663         final DefaultPool pool1 = new DefaultPool( A.class, 5, 10 );
664         pool1.setLogger(logger);
665         final long pool1Start = System.currentTimeMillis();
666         final int pool1Factor = 1;
667         final int pool1Loops = TEST_SIZE / pool1Factor;
668
669         for( int i = 0; i < TEST_SIZE; i++ )
670         {
671             final Poolable a1 = pool1.get();
672             pool1.put(a1);
673         }
674         final long pool1End = System.currentTimeMillis();
675         final long pool1Duration = pool1End - pool1Start;
676
677         System.gc();
678         System.gc();
679         Thread.currentThread().sleep(2);
680
681         if (logger.isDebugEnabled()) logger.debug("FreeMem post 1: " + Runtime.getRuntime().freeMemory() );
682
683         final DefaultPool pool2 = new DefaultPool( A.class, 5, 10 );
684         pool2.setLogger(logger);
685         final long pool2Start = System.currentTimeMillis();
686         final int pool2Factor = 10;
687         final int pool2Loops = TEST_SIZE / pool2Factor;
688
689         for( int i = 0; i < pool2Loops; i++ )
690         {
691             final Poolable a1 = pool2.get();
692             final Poolable a2 = pool2.get();
693             final Poolable a3 = pool2.get();
694             final Poolable a4 = pool2.get();
695             final Poolable a5 = pool2.get();
696             final Poolable a6 = pool2.get();
697             final Poolable a7 = pool2.get();
698             final Poolable a8 = pool2.get();
699             final Poolable a9 = pool2.get();
700             final Poolable a0 = pool2.get();
701             pool2.put(a1);
702             pool2.put(a2);
703             pool2.put(a3);
704             pool2.put(a4);
705             pool2.put(a5);
706             pool2.put(a6);
707             pool2.put(a7);
708             pool2.put(a8);
709             pool2.put(a9);
710             pool2.put(a0);
711         }
712         final long pool2End = System.currentTimeMillis();
713         final long pool2Duration = pool2End - pool2Start;
714
715         System.gc();
716         System.gc();
717         Thread.currentThread().sleep(2);
718
719         if (logger.isDebugEnabled()) logger.debug("FreeMem post 2: " + Runtime.getRuntime().freeMemory() );
720
721         final DefaultPool pool3 = new DefaultPool( A.class, 5, 10 );
722         pool3.setLogger(logger);
723         final long pool3Start = System.currentTimeMillis();
724         final int pool3Factor = 15;
725         final int pool3Loops = TEST_SIZE / pool3Factor;
726
727         for( int i = 0; i < pool3Loops; i++ )
728         {
729             final Poolable a1 = pool3.get();
730             final Poolable a2 = pool3.get();
731             final Poolable a3 = pool3.get();
732             final Poolable a4 = pool3.get();
733             final Poolable a5 = pool3.get();
734             final Poolable a6 = pool3.get();
735             final Poolable a7 = pool3.get();
736             final Poolable a8 = pool3.get();
737             final Poolable a9 = pool3.get();
738             final Poolable a10 = pool3.get();
739             final Poolable a11 = pool3.get();
740             final Poolable a12 = pool3.get();
741             final Poolable a13 = pool3.get();
742             final Poolable a14 = pool3.get();
743             final Poolable a15 = pool3.get();
744             pool3.put(a1);
745             pool3.put(a2);
746             pool3.put(a3);
747             pool3.put(a4);
748             pool3.put(a5);
749             pool3.put(a6);
750             pool3.put(a7);
751             pool3.put(a8);
752             pool3.put(a9);
753             pool3.put(a10);
754             pool3.put(a11);
755             pool3.put(a12);
756             pool3.put(a13);
757             pool3.put(a14);
758             pool3.put(a15);
759         }
760         final long pool3End = System.currentTimeMillis();
761         final long pool3Duration = pool3End - pool3Start;
762
763         System.gc();
764         System.gc();
765         Thread.currentThread().sleep(2);
766
767         if (logger.isDebugEnabled()) logger.debug("FreeMem post 3: " + Runtime.getRuntime().freeMemory() );
768
769         final DefaultPool pool4 = new DefaultPool( A.class, 5, 10 );
770         pool4.setLogger(logger);
771         final long pool4Start = System.currentTimeMillis();
772         final int pool4Factor = 20;
773         final int pool4Loops = TEST_SIZE / pool4Factor;
774
775         for( int i = 0; i < pool4Loops; i++ )
776         {
777             final Poolable a1 = pool4.get();
778             final Poolable a2 = pool4.get();
779             final Poolable a3 = pool4.get();
780             final Poolable a4 = pool4.get();
781             final Poolable a5 = pool4.get();
782             final Poolable a6 = pool4.get();
783             final Poolable a7 = pool4.get();
784             final Poolable a8 = pool4.get();
785             final Poolable a9 = pool4.get();
786             final Poolable a10 = pool4.get();
787             final Poolable a11 = pool4.get();
788             final Poolable a12 = pool4.get();
789             final Poolable a13 = pool4.get();
790             final Poolable a14 = pool4.get();
791             final Poolable a15 = pool4.get();
792             final Poolable a16 = pool4.get();
793             final Poolable a17 = pool4.get();
794             final Poolable a18 = pool4.get();
795             final Poolable a19 = pool4.get();
796             final Poolable a20 = pool4.get();
797             pool4.put(a1);
798             pool4.put(a2);
799             pool4.put(a3);
800             pool4.put(a4);
801             pool4.put(a5);
802             pool4.put(a6);
803             pool4.put(a7);
804             pool4.put(a8);
805             pool4.put(a9);
806             pool4.put(a10);
807             pool4.put(a11);
808             pool4.put(a12);
809             pool4.put(a13);
810             pool4.put(a14);
811             pool4.put(a15);
812             pool4.put(a16);
813             pool4.put(a17);
814             pool4.put(a18);
815             pool4.put(a19);
816             pool4.put(a20);
817         }
818         final long pool4End = System.currentTimeMillis();
819         final long pool4Duration = pool4End - pool4Start;
820
821         if (logger.isDebugEnabled()) logger.debug("FreeMem post 4: " + Runtime.getRuntime().freeMemory() );
822
823         final long createStart = System.currentTimeMillis();
824         for( int i = 0; i < TEST_SIZE; i++ )
825         {
826             final Poolable a1 = new C();
827         }
828         final long createEnd = System.currentTimeMillis();
829         final long createDuration = createEnd - createStart;
830
831         if (logger.isDebugEnabled()) logger.debug("Create Duration: " + createDuration + "ms ");
832         if (logger.isDebugEnabled()) logger.debug("FreeMem post create: " + Runtime.getRuntime().freeMemory() );
833
834         final double pool1Efficiency = (double)createDuration/(double)pool1Duration * 100.0;
835         final double pool2Efficiency = (double)createDuration/(double)pool2Duration * 100.0;
836         final double pool3Efficiency = (double)createDuration/(double)pool3Duration * 100.0;
837         final double pool4Efficiency = (double)createDuration/(double)pool4Duration * 100.0;
838
839         if (logger.isDebugEnabled()) logger.debug("Pool Efficiency for 100% hits: " + pool1Efficiency + "% ");
840         if (logger.isInfoEnabled()) logger.info("Time Saved for 100% hits: " + (createDuration - pool1Duration) + "ms ");
841
842         if (logger.isDebugEnabled()) logger.debug("Pool Efficiency for 100% hits and saturated: " + pool2Efficiency + "% ");
843         if (logger.isInfoEnabled()) logger.info("Time Saved for 100% hits: " + (createDuration - pool2Duration) + "ms ");
844
845         if (logger.isDebugEnabled()) logger.debug("Pool Efficiency for 60% hits: " + pool3Efficiency + "% ");
846         if (logger.isInfoEnabled()) logger.info("Time Saved for 60% hits: " + (createDuration - pool3Duration) + "ms ");
847
848         if (logger.isDebugEnabled()) logger.debug("Pool Efficiency for 50% hits: " + pool4Efficiency + "% ");
849         if (logger.isInfoEnabled()) logger.info("Time Saved for 50% hits: " + (createDuration - pool4Duration) + "ms ");
850     }
851
852     public void testThreadedMediumObjects()
853         throws Exception JavaDoc
854     {
855         logger.info("MEDIUM Sized Objects with thread safe pools");
856
857         System.gc();
858         System.gc();
859         Thread.currentThread().sleep(2);
860
861         final DefaultPool pool1 = new DefaultPool( B.class, 5, 10 );
862         pool1.setLogger(logger);
863         final long pool1Start = System.currentTimeMillis();
864         final int pool1Factor = 1;
865         final int pool1Loops = TEST_SIZE / pool1Factor;
866
867         for( int i = 0; i < TEST_SIZE; i++ )
868         {
869             final Poolable a1 = pool1.get();
870             pool1.put(a1);
871         }
872         final long pool1End = System.currentTimeMillis();
873         final long pool1Duration = pool1End - pool1Start;
874
875         System.gc();
876         System.gc();
877         Thread.currentThread().sleep(2);
878
879         if (logger.isDebugEnabled()) logger.debug("FreeMem post 1: " + Runtime.getRuntime().freeMemory() );
880
881         final DefaultPool pool2 = new DefaultPool( B.class, 5, 10 );
882         pool2.setLogger(logger);
883         final long pool2Start = System.currentTimeMillis();
884         final int pool2Factor = 10;
885         final int pool2Loops = TEST_SIZE / pool2Factor;
886
887         for( int i = 0; i < pool2Loops; i++ )
888         {
889             final Poolable a1 = pool2.get();
890             final Poolable a2 = pool2.get();
891             final Poolable a3 = pool2.get();
892             final Poolable a4 = pool2.get();
893             final Poolable a5 = pool2.get();
894             final Poolable a6 = pool2.get();
895             final Poolable a7 = pool2.get();
896             final Poolable a8 = pool2.get();
897             final Poolable a9 = pool2.get();
898             final Poolable a10 = pool2.get();
899             /*
900               a1.build();
901               a2.build();
902               a3.build();
903               a4.build();
904               a5.build();
905               a6.build();
906               a7.build();
907               a8.build();
908               a9.build();
909               a10.build();
910             */

911             pool2.put(a1);
912             pool2.put(a2);
913             pool2.put(a3);
914             pool2.put(a4);
915             pool2.put(a5);
916             pool2.put(a6);
917             pool2.put(a7);
918             pool2.put(a8);
919             pool2.put(a9);
920             pool2.put(a10);
921         }
922         final long pool2End = System.currentTimeMillis();
923         final long pool2Duration = pool2End - pool2Start;
924
925         System.gc();
926         System.gc();
927         Thread.currentThread().sleep(2);
928
929         if (logger.isDebugEnabled()) logger.debug("FreeMem post 2: " + Runtime.getRuntime().freeMemory() );
930
931         final DefaultPool pool3 = new DefaultPool( B.class, 5, 10 );
932         pool3.setLogger(logger);
933         final long pool3Start = System.currentTimeMillis();
934         final int pool3Factor = 15;
935         final int pool3Loops = TEST_SIZE / pool3Factor;
936
937         for( int i = 0; i < pool3Loops; i++ )
938         {
939             final Poolable a1 = pool3.get();
940             final Poolable a2 = pool3.get();
941             final Poolable a3 = pool3.get();
942             final Poolable a4 = pool3.get();
943             final Poolable a5 = pool3.get();
944             final Poolable a6 = pool3.get();
945             final Poolable a7 = pool3.get();
946             final Poolable a8 = pool3.get();
947             final Poolable a9 = pool3.get();
948             final Poolable a10 = pool3.get();
949             final Poolable a11 = pool3.get();
950             final Poolable a12 = pool3.get();
951             final Poolable a13 = pool3.get();
952             final Poolable a14 = pool3.get();
953             final Poolable a15 = pool3.get();
954             /*
955               a1.build();
956               a2.build();
957               a3.build();
958               a4.build();
959               a5.build();
960               a6.build();
961               a7.build();
962               a8.build();
963               a9.build();
964               a10.build();
965               a11.build();
966               a12.build();
967               a13.build();
968               a14.build();
969               a15.build();
970             */

971             pool3.put(a1);
972             pool3.put(a2);
973             pool3.put(a3);
974             pool3.put(a4);
975             pool3.put(a5);
976             pool3.put(a6);
977             pool3.put(a7);
978             pool3.put(a8);
979             pool3.put(a9);
980             pool3.put(a10);
981             pool3.put(a11);
982             pool3.put(a12);
983             pool3.put(a13);
984             pool3.put(a14);
985             pool3.put(a15);
986         }
987         final long pool3End = System.currentTimeMillis();
988         final long pool3Duration = pool3End - pool3Start;
989
990         System.gc();
991         System.gc();
992         Thread.currentThread().sleep(2);
993
994         if (logger.isDebugEnabled()) logger.debug("FreeMem post 3: " + Runtime.getRuntime().freeMemory() );
995
996         final DefaultPool pool4 = new DefaultPool( B.class, 5, 10 );
997         pool4.setLogger(logger);
998         final long pool4Start = System.currentTimeMillis();
999         final int pool4Factor = 20;
1000        final int pool4Loops = TEST_SIZE / pool4Factor;
1001
1002        for( int i = 0; i < pool4Loops; i++ )
1003        {
1004            final Poolable a1 = pool4.get();
1005            final Poolable a2 = pool4.get();
1006            final Poolable a3 = pool4.get();
1007            final Poolable a4 = pool4.get();
1008            final Poolable a5 = pool4.get();
1009            final Poolable a6 = pool4.get();
1010            final Poolable a7 = pool4.get();
1011            final Poolable a8 = pool4.get();
1012            final Poolable a9 = pool4.get();
1013            final Poolable a10 = pool4.get();
1014            final Poolable a11 = pool4.get();
1015            final Poolable a12 = pool4.get();
1016            final Poolable a13 = pool4.get();
1017            final Poolable a14 = pool4.get();
1018            final Poolable a15 = pool4.get();
1019            final Poolable a16 = pool4.get();
1020            final Poolable a17 = pool4.get();
1021            final Poolable a18 = pool4.get();
1022            final Poolable a19 = pool4.get();
1023            final Poolable a20 = pool4.get();
1024            /*
1025              a1.build();
1026              a2.build();
1027              a3.build();
1028              a4.build();
1029              a5.build();
1030              a6.build();
1031              a7.build();
1032              a8.build();
1033              a9.build();
1034              a10.build();
1035              a11.build();
1036              a12.build();
1037              a13.build();
1038              a14.build();
1039              a15.build();
1040              a16.build();
1041              a17.build();
1042              a18.build();
1043              a19.build();
1044              a20.build();
1045            */

1046            pool4.put(a1);
1047            pool4.put(a2);
1048            pool4.put(a3);
1049            pool4.put(a4);
1050            pool4.put(a5);
1051            pool4.put(a6);
1052            pool4.put(a7);
1053            pool4.put(a8);
1054            pool4.put(a9);
1055            pool4.put(a10);
1056            pool4.put(a11);
1057            pool4.put(a12);
1058            pool4.put(a13);
1059            pool4.put(a14);
1060            pool4.put(a15);
1061            pool4.put(a16);
1062            pool4.put(a17);
1063            pool4.put(a18);
1064            pool4.put(a19);
1065            pool4.put(a20);
1066        }
1067        final long pool4End = System.currentTimeMillis();
1068        final long pool4Duration = pool4End - pool4Start;
1069
1070        final long createStart = System.currentTimeMillis();
1071        for( int i = 0; i < TEST_SIZE; i++ )
1072        {
1073            final Poolable a1 = new C();
1074        }
1075        final long createEnd = System.currentTimeMillis();
1076        final long createDuration = createEnd - createStart;
1077
1078        if (logger.isDebugEnabled()) logger.debug("Create Duration: " + createDuration + "ms ");
1079        if (logger.isDebugEnabled()) logger.debug("FreeMem post create: " + Runtime.getRuntime().freeMemory() );
1080
1081        final double pool1Efficiency = (double)createDuration/(double)pool1Duration * 100.0;
1082        final double pool2Efficiency = (double)createDuration/(double)pool2Duration * 100.0;
1083        final double pool3Efficiency = (double)createDuration/(double)pool3Duration * 100.0;
1084        final double pool4Efficiency = (double)createDuration/(double)pool4Duration * 100.0;
1085
1086        if (logger.isDebugEnabled()) logger.debug("Pool Efficiency for 100% hits: " + pool1Efficiency + "% ");
1087        if (logger.isInfoEnabled()) logger.info("Time Saved for 100% hits: " + (createDuration - pool1Duration) + "ms ");
1088
1089        if (logger.isDebugEnabled()) logger.debug("Pool Efficiency for 100% hits and saturated: " + pool2Efficiency + "% ");
1090        if (logger.isInfoEnabled()) logger.info("Time Saved for 100% hits: " + (createDuration - pool2Duration) + "ms ");
1091
1092        if (logger.isDebugEnabled()) logger.debug("Pool Efficiency for 60% hits: " + pool3Efficiency + "% ");
1093        if (logger.isInfoEnabled()) logger.info("Time Saved for 60% hits: " + (createDuration - pool3Duration) + "ms ");
1094
1095        if (logger.isDebugEnabled()) logger.debug("Pool Efficiency for 50% hits: " + pool4Efficiency + "% ");
1096        if (logger.isInfoEnabled()) logger.info("Time Saved for 50% hits: " + (createDuration - pool4Duration) + "ms ");
1097    }
1098
1099    public void testThreadedLargeObjects()
1100        throws Exception JavaDoc
1101    {
1102        logger.info("LARGE Sized Objects with thread safe pools");
1103
1104        System.gc();
1105        System.gc();
1106        Thread.currentThread().sleep(2);
1107
1108        final DefaultPool pool1 = new DefaultPool( C.class, 5, 10 );
1109        pool1.setLogger(logger);
1110        final long pool1Start = System.currentTimeMillis();
1111        final int pool1Factor = 1;
1112        final int pool1Loops = TEST_SIZE / pool1Factor;
1113
1114        for( int i = 0; i < TEST_SIZE; i++ )
1115        {
1116            final Poolable a1 = pool1.get();
1117            //a1.build();
1118
pool1.put(a1);
1119        }
1120        final long pool1End = System.currentTimeMillis();
1121        final long pool1Duration = pool1End - pool1Start;
1122
1123        System.gc();
1124        System.gc();
1125        Thread.currentThread().sleep(2);
1126
1127        if (logger.isDebugEnabled()) logger.debug("FreeMem post 1: " + Runtime.getRuntime().freeMemory() );
1128
1129        final DefaultPool pool2 = new DefaultPool( C.class, 5, 10 );
1130        pool2.setLogger(logger);
1131        final long pool2Start = System.currentTimeMillis();
1132        final int pool2Factor = 10;
1133        final int pool2Loops = TEST_SIZE / pool2Factor;
1134
1135        for( int i = 0; i < pool2Loops; i++ )
1136        {
1137            final Poolable a1 = pool2.get();
1138            final Poolable a2 = pool2.get();
1139            final Poolable a3 = pool2.get();
1140            final Poolable a4 = pool2.get();
1141            final Poolable a5 = pool2.get();
1142            final Poolable a6 = pool2.get();
1143            final Poolable a7 = pool2.get();
1144            final Poolable a8 = pool2.get();
1145            final Poolable a9 = pool2.get();
1146            final Poolable a10 = pool2.get();
1147            /*
1148              a1.build();
1149              a2.build();
1150              a3.build();
1151              a4.build();
1152              a5.build();
1153              a6.build();
1154              a7.build();
1155              a8.build();
1156              a9.build();
1157              a10.build();
1158            */

1159            pool2.put(a1);
1160            pool2.put(a2);
1161            pool2.put(a3);
1162            pool2.put(a4);
1163            pool2.put(a5);
1164            pool2.put(a6);
1165            pool2.put(a7);
1166            pool2.put(a8);
1167            pool2.put(a9);
1168            pool2.put(a10);
1169        }
1170        final long pool2End = System.currentTimeMillis();
1171        final long pool2Duration = pool2End - pool2Start;
1172
1173        System.gc();
1174        System.gc();
1175        Thread.currentThread().sleep(2);
1176
1177        if (logger.isDebugEnabled()) logger.debug("FreeMem post 2: " + Runtime.getRuntime().freeMemory() );
1178
1179        final DefaultPool pool3 = new DefaultPool( C.class, 5, 10 );
1180        pool3.setLogger(logger);
1181        final long pool3Start = System.currentTimeMillis();
1182        final int pool3Factor = 15;
1183        final int pool3Loops = TEST_SIZE / pool3Factor;
1184
1185        for( int i = 0; i < pool3Loops; i++ )
1186        {
1187            final Poolable a1 = pool3.get();
1188            final Poolable a2 = pool3.get();
1189            final Poolable a3 = pool3.get();
1190            final Poolable a4 = pool3.get();
1191            final Poolable a5 = pool3.get();
1192            final Poolable a6 = pool3.get();
1193            final Poolable a7 = pool3.get();
1194            final Poolable a8 = pool3.get();
1195            final Poolable a9 = pool3.get();
1196            final Poolable a10 = pool3.get();
1197            final Poolable a11 = pool3.get();
1198            final Poolable a12 = pool3.get();
1199            final Poolable a13 = pool3.get();
1200            final Poolable a14 = pool3.get();
1201            final Poolable a15 = pool3.get();
1202            /*
1203              a1.build();
1204              a2.build();
1205              a3.build();
1206              a4.build();
1207              a5.build();
1208              a6.build();
1209              a7.build();
1210              a8.build();
1211              a9.build();
1212              a10.build();
1213              a11.build();
1214              a12.build();
1215              a13.build();
1216              a14.build();
1217              a15.build();
1218            */

1219            pool3.put(a1);
1220            pool3.put(a2);
1221            pool3.put(a3);
1222            pool3.put(a4);
1223            pool3.put(a5);
1224            pool3.put(a6);
1225            pool3.put(a7);
1226            pool3.put(a8);
1227            pool3.put(a9);
1228            pool3.put(a10);
1229            pool3.put(a11);
1230            pool3.put(a12);
1231            pool3.put(a13);
1232            pool3.put(a14);
1233            pool3.put(a15);
1234        }
1235        final long pool3End = System.currentTimeMillis();
1236        final long pool3Duration = pool3End - pool3Start;
1237
1238        System.gc();
1239        System.gc();
1240        Thread.currentThread().sleep(2);
1241
1242        if (logger.isDebugEnabled()) logger.debug("FreeMem post 3: " + Runtime.getRuntime().freeMemory() );
1243
1244        final DefaultPool pool4 = new DefaultPool( C.class, 5, 10 );
1245        pool4.setLogger(logger);
1246        final long pool4Start = System.currentTimeMillis();
1247        final int pool4Factor = 20;
1248        final int pool4Loops = TEST_SIZE / pool4Factor;
1249
1250        for( int i = 0; i < pool4Loops; i++ )
1251        {
1252            final Poolable a1 = pool4.get();
1253            final Poolable a2 = pool4.get();
1254            final Poolable a3 = pool4.get();
1255            final Poolable a4 = pool4.get();
1256            final Poolable a5 = pool4.get();
1257            final Poolable a6 = pool4.get();
1258            final Poolable a7 = pool4.get();
1259            final Poolable a8 = pool4.get();
1260            final Poolable a9 = pool4.get();
1261            final Poolable a10 = pool4.get();
1262            final Poolable a11 = pool4.get();
1263            final Poolable a12 = pool4.get();
1264            final Poolable a13 = pool4.get();
1265            final Poolable a14 = pool4.get();
1266            final Poolable a15 = pool4.get();
1267            final Poolable a16 = pool4.get();
1268            final Poolable a17 = pool4.get();
1269            final Poolable a18 = pool4.get();
1270            final Poolable a19 = pool4.get();
1271            final Poolable a20 = pool4.get();
1272            pool4.put(a1);
1273            pool4.put(a2);
1274            pool4.put(a3);
1275            pool4.put(a4);
1276            pool4.put(a5);
1277            pool4.put(a6);
1278            pool4.put(a7);
1279            pool4.put(a8);
1280            pool4.put(a9);
1281            pool4.put(a10);
1282            pool4.put(a11);
1283            pool4.put(a12);
1284            pool4.put(a13);
1285            pool4.put(a14);
1286            pool4.put(a15);
1287            pool4.put(a16);
1288            pool4.put(a17);
1289            pool4.put(a18);
1290            pool4.put(a19);
1291            pool4.put(a20);
1292        }
1293        final long pool4End = System.currentTimeMillis();
1294        final long pool4Duration = pool4End - pool4Start;
1295
1296        if (logger.isDebugEnabled()) logger.debug("FreeMem post 4: " + Runtime.getRuntime().freeMemory() );
1297
1298        final long createStart = System.currentTimeMillis();
1299        for( int i = 0; i < TEST_SIZE; i++ )
1300        {
1301            final Poolable a1 = new C();
1302        }
1303        final long createEnd = System.currentTimeMillis();
1304        final long createDuration = createEnd - createStart;
1305
1306        if (logger.isDebugEnabled()) logger.debug("FreeMem post create: " + Runtime.getRuntime().freeMemory() );
1307
1308        final double pool1Efficiency = (double)createDuration/(double)pool1Duration * 100.0;
1309        final double pool2Efficiency = (double)createDuration/(double)pool2Duration * 100.0;
1310        final double pool3Efficiency = (double)createDuration/(double)pool3Duration * 100.0;
1311        final double pool4Efficiency = (double)createDuration/(double)pool4Duration * 100.0;
1312
1313        if (logger.isDebugEnabled()) logger.debug("Pool Efficiency for 100% hits: " + pool1Efficiency + "% ");
1314        if (logger.isInfoEnabled()) logger.info("Time Saved for 100% hits: " + (createDuration - pool1Duration) + "ms ");
1315
1316        if (logger.isDebugEnabled()) logger.debug("Pool Efficiency for 100% hits and saturated: " + pool2Efficiency + "% ");
1317        if (logger.isInfoEnabled()) logger.info("Time Saved for 100% hits: " + (createDuration - pool2Duration) + "ms ");
1318
1319        if (logger.isDebugEnabled()) logger.debug("Pool Efficiency for 60% hits: " + pool3Efficiency + "% ");
1320        if (logger.isInfoEnabled()) logger.info("Time Saved for 60% hits: " + (createDuration - pool3Duration) + "ms ");
1321
1322        if (logger.isDebugEnabled()) logger.debug("Pool Efficiency for 50% hits: " + pool4Efficiency + "% ");
1323        if (logger.isInfoEnabled()) logger.info("Time Saved for 50% hits: " + (createDuration - pool4Duration) + "ms ");
1324    }
1325}
1326
Popular Tags