1 17 package org.apache.excalibur.mpool.test; 18 19 import org.apache.avalon.excalibur.pool.Poolable; 20 import org.apache.avalon.framework.activity.Disposable; 21 import org.apache.excalibur.mpool.Pool; 22 23 30 public class SingleThreadedPoolComparisonProfile 31 extends PoolComparisonProfileAbstract 32 { 33 36 public SingleThreadedPoolComparisonProfile( String name ) 37 { 38 super( name ); 39 } 40 41 44 protected long getPoolRunTime( Pool pool, int gets ) 45 throws Exception 46 { 47 resetMemory(); 49 50 final long startTime = System.currentTimeMillis(); 51 final Object [] poolTmp = new Object [ gets ]; 52 final int loops = TEST_SIZE / gets; 53 for( int i = 0; i < loops; i++ ) 54 { 55 for( int j = 0; j < gets; j++ ) 57 { 58 poolTmp[ j ] = pool.acquire(); 59 } 60 61 for( int j = 0; j < gets; j++ ) 63 { 64 pool.release( poolTmp[ j ] ); 65 poolTmp[ j ] = null; 66 } 67 } 68 final long duration = System.currentTimeMillis() - startTime; 69 70 if( pool instanceof Disposable ) 72 { 73 ( (Disposable)pool ).dispose(); 74 } 75 76 return duration; 77 } 78 79 82 protected long getPoolRunTime( org.apache.avalon.excalibur.pool.Pool pool, int gets ) 83 throws Exception 84 { 85 resetMemory(); 87 88 final long startTime = System.currentTimeMillis(); 89 final Poolable[] poolTmp = new Poolable[ gets ]; 90 final int loops = TEST_SIZE / gets; 91 for( int i = 0; i < loops; i++ ) 92 { 93 for( int j = 0; j < gets; j++ ) 95 { 96 poolTmp[ j ] = pool.get(); 97 } 98 99 for( int j = 0; j < gets; j++ ) 101 { 102 pool.put( poolTmp[ j ] ); 103 poolTmp[ j ] = null; 104 } 105 } 106 final long duration = System.currentTimeMillis() - startTime; 107 108 if( pool instanceof Disposable ) 110 { 111 ( (Disposable)pool ).dispose(); 112 } 113 114 return duration; 115 } 116 } 117 | Popular Tags |