[hibernate-commits] Hibernate SVN: r14019 - sandbox/trunk/jdbc-proxy/src/test/perf/org/hibernate/jdbc.

hibernate-commits at lists.jboss.org hibernate-commits at lists.jboss.org
Fri Sep 21 12:26:29 EDT 2007


Author: steve.ebersole at jboss.com
Date: 2007-09-21 12:26:29 -0400 (Fri, 21 Sep 2007)
New Revision: 14019

Modified:
   sandbox/trunk/jdbc-proxy/src/test/perf/org/hibernate/jdbc/PerformanceTest.java
Log:
more robust forced gc to better isolate runs

Modified: sandbox/trunk/jdbc-proxy/src/test/perf/org/hibernate/jdbc/PerformanceTest.java
===================================================================
--- sandbox/trunk/jdbc-proxy/src/test/perf/org/hibernate/jdbc/PerformanceTest.java	2007-09-21 16:24:13 UTC (rev 14018)
+++ sandbox/trunk/jdbc-proxy/src/test/perf/org/hibernate/jdbc/PerformanceTest.java	2007-09-21 16:26:29 UTC (rev 14019)
@@ -15,6 +15,7 @@
  */
 package org.hibernate.jdbc;
 
+import java.lang.ref.WeakReference;
 import java.sql.Connection;
 import java.sql.PreparedStatement;
 import java.sql.ResultSet;
@@ -126,11 +127,8 @@
 			}
 		}
 
-		System.gc();
-		System.gc();
+		// prime ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~p~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
-		// prime ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
 		for ( int a = 0, Z = datums.length; a < Z; a++ ) {
 			process( datums[a], 1 );
 		}
@@ -157,6 +155,15 @@
 		System.out.println( "-----------------------------------------------------------------------------------" );
 	}
 
+	private void doGC() throws Throwable {
+		WeakReference dumb = new WeakReference( new Object() );
+		System.gc();
+		System.gc();
+		while ( dumb.get() != null) {
+			Thread.sleep( 500 );
+		}
+	}
+
 	private ProcessResult average(ProcessResult[][] results, int extrapolation) {
 		long jdbcAvg = 0, proxyAvg = 0, delegAvg = 0;
 		// the first dimension is the object counts...
@@ -205,6 +212,8 @@
 		LogicalConnectionImpl lc;
 		long start;
 
+		doGC();
+
 		start = System.currentTimeMillis();
 		c = services.getConnectionProvider().getConnection();
 		for ( int i = 0; i < statementCount; i++ ) {
@@ -213,6 +222,8 @@
 		services.getConnectionProvider().closeConnection( c );
 		long jdbc = System.currentTimeMillis() - start;
 
+		doGC();
+
 		start = System.currentTimeMillis();
 		lc = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_TRANSACTION, services );
 		c = ProxyBuilder.buildConnection( lc );
@@ -223,6 +234,8 @@
 		lc.close();
 		long proxy = System.currentTimeMillis() - start;
 
+		doGC();
+
 		start = System.currentTimeMillis();
 		lc = new LogicalConnectionImpl( null, ConnectionReleaseMode.AFTER_TRANSACTION, services );
 		c = new ConnectionDelegate( lc );




More information about the hibernate-commits mailing list