FileDocCategorySizeDatePackage
NewPerformanceTest.javaAPI DocHibernate 3.2.52390Sun Feb 13 16:01:34 GMT 2005org.hibernate.test.legacy

NewPerformanceTest

public class NewPerformanceTest extends org.hibernate.test.TestCase

Fields Summary
Constructors Summary
public NewPerformanceTest(String arg0)

		super(arg0);
	
Methods Summary
private voiddelete(org.hibernate.classic.Session s)

		s.delete("from Simple s");
		s.flush();
		s.connection().commit();
	
public java.lang.String[]getMappings()

		return new String[] { "legacy/Simple.hbm.xml" };
	
public static voidmain(java.lang.String[] args)

		TestRunner.run( suite() );
	
private voidprepare(org.hibernate.classic.Session s, Simple[] simples, java.io.Serializable[] ids, int N)

		for ( int i=0; i<N; i++ ) {
			s.save( simples[i], ids[i] );
		}
		s.flush();
		s.connection().commit();
	
public static junit.framework.Testsuite()

		return new TestSuite(NewPerformanceTest.class);
	
public voidtestPerformance()


		for ( int n=2; n<4000; n*=2 ) {

			Simple[] simples = new Simple[n];
			Serializable[] ids = new Serializable[n];
			for ( int i=0; i<n; i++ ) {
				simples[i] = new Simple();
				simples[i].init();
				simples[i].setCount(i);
				ids[i] = new Long(i);
			}

			Session s = openSession();
			prepare(s, simples, ids, n);
			s.close();

			long find = 0;
			long flush = 0;

			for ( int i=0; i<100; i++ ) {

				s = openSession();
				long time = System.currentTimeMillis();
				List list = s.createQuery("from Simple s where not s.name='osama bin laden' and s.other is null").list();
				find += System.currentTimeMillis() - time;
				assertTrue( list.size()==n );
				time = System.currentTimeMillis();
				s.flush();
				flush += System.currentTimeMillis() - time;
				time = System.currentTimeMillis();
				s.connection().commit();
				find += System.currentTimeMillis() - time;
				s.close();

			}

			System.out.println( "Objects: " + n + " - find(): " + find + "ms / flush(): " + flush + "ms / Ratio: " + ( (float) flush )/find );
			System.out.println( "Objects: " + n + " flush time per object: " + flush / 100.0 / n );
			System.out.println( "Objects: " + n + " load time per object: " + find / 100.0 / n );
			s = openSession();
			delete(s);
			s.close();

		}