for ( int n=2; n<4000; n*=2 ) { Session s = openSession(); Simple[] simples = new Simple[n]; s.delete("from Simple"); s.flush(); 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); s.save(simples[i], ids[i]); } s.flush(); s.connection().commit(); s.close(); //Now do timings s = openSession(); long time = System.currentTimeMillis(); hibernate(s, simples, ids, n, "h1"); long hiber = System.currentTimeMillis() - time; s.close(); s = openSession(); time = System.currentTimeMillis(); hibernate(s, simples, ids, n, "h2"); hiber += System.currentTimeMillis() - time; s.close(); s = openSession(); time = System.currentTimeMillis(); hibernate(s, simples, ids, n, "h2"); hiber += System.currentTimeMillis() - time; s.close(); System.out.println( "Objects: " + n + " - Hibernate: " + hiber ); } System.gc();
Session s = openSession(); Simple[] simples = new Simple[n]; s.delete("from Simple"); s.flush(); 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); s.save(simples[i], ids[i]); } s.flush(); s.connection().commit(); s.close(); //Now do timings Connection c = cp.getConnection(); long time = System.currentTimeMillis(); directJDBC( c, simples, ids, n, "j1" ); long jdbc = System.currentTimeMillis() - time; cp.closeConnection(c); c = cp.getConnection(); time = System.currentTimeMillis(); directJDBC( c, simples, ids, n, "j2" ); jdbc += System.currentTimeMillis() - time; cp.closeConnection(c); c = cp.getConnection(); time = System.currentTimeMillis(); directJDBC( c, simples, ids, n, "j2" ); jdbc += System.currentTimeMillis() - time; cp.closeConnection(c); System.out.println( "Objects: " + n + " Direct JDBC: " + jdbc );
Clone fragments detected by clone detection tool
File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/perf/org/hibernate/test/perf/NewerPerformanceTest.java File path: /hibernate-distribution-3.3.2.GA/project/testsuite/src/test/perf/org/hibernate/test/perf/NewerPerformanceTest.java
Method name: void testHibernateOnly() Method name: void testJdbcOnly()
Number of AST nodes: 32 Number of AST nodes: 30
1
for ( int n=2; n<4000; n*=2 ) {
2
			Session s = openSession();
1
Session s = openSession();
3
			Simple[] simples = new Simple[n];
2
			Simple[] simples = new Simple[n];
4
			s.delete("from Simple");
3
			s.delete("from Simple");
5
			s.flush();
4
			s.flush();
6
			Serializable[] ids = new Serializable[n];
5
			Serializable[] ids = new Serializable[n];
7
			for ( int i=0; i<n; i++ ) {
6
			for ( int i=0; i<n; i++ ) {
8
				simples[i] = new Simple();
7
				simples[i] = new Simple();
9
				simples[i].init();
8
				simples[i].init();
10
				simples[i].setCount(i);
9
				simples[i].setCount(i);
11
				ids[i] = new Long(i);
10
				ids[i] = new Long(i);
12
				s.save(simples[i], ids[i]);
11
				s.save(simples[i], ids[i]);
13
			}
12
			}
14
			s.flush();
13
			s.flush();
15
			s.connection().commit();
14
			s.connection().commit();
16
			s.close();
15
			s.close();
17
			//Now do timings
16
			//Now do timings
18
			s = openSession();
17
			Connection c = cp.getConnection();
19
			long time = System.currentTimeMillis();
18
			long time = System.currentTimeMillis();
20
			hibernate(s, simples, ids, n, "h1");
19
			directJDBC( c, simples, ids, n, "j1" );
21
			long hiber = System.currentTimeMillis() - time;
20
			long jdbc = System.currentTimeMillis() - time;
22
			s.close();
21
			cp.closeConnection(c);
23
			s = openSession();
22
			c = cp.getConnection();
24
			time = System.currentTimeMillis();
23
			time = System.currentTimeMillis();
25
			hibernate(s, simples, ids, n, "h2");
24
			directJDBC( c, simples, ids, n, "j2" );
26
			hiber += System.currentTimeMillis() - time;
25
			jdbc += System.currentTimeMillis() - time;
27
			s.close();
26
			cp.closeConnection(c);
28
			s = openSession();
27
			c = cp.getConnection();
29
			time = System.currentTimeMillis();
28
			time = System.currentTimeMillis();
30
			hibernate(s, simples, ids, n, "h2");
29
			directJDBC( c, simples, ids, n, "j2" );
31
			hiber += System.currentTimeMillis() - time;
30
			jdbc += System.currentTimeMillis() - time;
32
			s.close();
31
			cp.closeConnection(c);
33
			System.out.println( "Objects: " + n + " - Hibernate: " + hiber );
32
			System.out.println( "Objects: " + n + " 
34
		}
35
		System.gc();
33
Direct JDBC: " + jdbc );
Summary
Number of common nesting structure subtrees1
Number of refactorable cases0
Number of non-refactorable cases1
Time elapsed for finding largest common nesting structure subtrees (ms)0.2
Clones locationClones are declared in the same class
Number of node comparisons375
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements24
    Number of unmapped statements in the first code fragment6
    Number of unmapped statements in the second code fragment6
    Time elapsed for statement mapping (ms)15.2
    Clone typeType 2
    Mapped Statements
    ID Statement ID Statement
    2
    Session s = openSession();
    3
    Session s = openSession();
    3
    Simple[] simples = new Simple[n];
    4
    Simple[] simples = new Simple[n];
    4
    s.delete("from Simple");
    5
    s.delete("from Simple");
    5
    s.flush();
    6
    s.flush();
    6
    Serializable[] ids = new Serializable[n];
    7
    Serializable[] ids = new Serializable[n];
    7
    for (int i = 0; i < n; i++)
    8
    for (int i = 0; i < n; i++)
    8
    simples[i] = new Simple();
    9
    simples[i] = new Simple();
    9
    simples[i].init();
    10
    simples[i].init();
    10
    simples[i].setCount(i);
    11
    simples[i].setCount(i);
    11
    ids[i] = new Long(i);
    12
    ids[i] = new Long(i);
    12
    s.save(simples[i], ids[i]);
    13
    s.save(simples[i], ids[i]);
    13
    s.flush();
    14
    s.flush();
    14
    s.connection().commit();
    15
    s.connection().commit();
    15
    s.close();
    16
    s.close();
    16
    s = openSession();
    16
    s = openSession();
    Preondition Violations
    Unmatched statement s=openSession(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                            
                                                                            
    17
    Connection c = cp.getConnection();
    Preondition Violations
    Unmatched statement Connection c=cp.getConnection(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    17
    Connection c = cp.getConnection();
    17
    long time = System.currentTimeMillis();
    18
    long time = System.currentTimeMillis();
                                                                              
    19
    directJDBC(c, simples, ids, n, "j1");
    Preondition Violations
    Unmatched statement directJDBC(c,simples,ids,n,"j1"); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    19
    directJDBC(c, simples, ids, n, "j1");
    18
    hibernate(s, simples, ids, n, "h1");
    18
    hibernate(s, simples, ids, n, "h1");
    21
    cp.closeConnection(c);
    Differences
    Expression1Expression2Difference
    hibernatecloseConnectionMETHOD_INVOCATION_NAME_MISMATCH
    hibernate(s,simples,ids,n,"h1")cp.closeConnection(c)ARGUMENT_NUMBER_MISMATCH
    cpMISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression hibernate(s,simples,ids,n,"h1") cannot be parameterized, because it has dependencies to/from statements that will be extracted
    • Inline private method hibernate
    Expression hibernate(s,simples,ids,n,"h1") is a void method call, and thus it cannot be parameterized
    Expression cp.closeConnection(c) is a void method call, and thus it cannot be parameterized
    Expression hibernate(s,simples,ids,n,"h1") cannot be parameterized, because it has dependencies to/from statements that will be extracted
    • Inline private method hibernate
    Expression hibernate(s,simples,ids,n,"h1") is a void method call, and thus it cannot be parameterized
    Expression cp.closeConnection(c) is a void method call, and thus it cannot be parameterized
    21
    cp.closeConnection(c);
    19
    long hiber = System.currentTimeMillis() - time;
    19
    long hiber = System.currentTimeMillis() - time;
    20
    long jdbc = System.currentTimeMillis() - time;
    Differences
    Expression1Expression2Difference
    hiberjdbcVARIABLE_NAME_MISMATCH
    20
    long jdbc = System.currentTimeMillis() - time;
    20
    s.close();
                                
    21
    s = openSession();
    21
    s = openSession();
    Preondition Violations
    Unmatched statement s=openSession(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                            
                                                      
    22
    c = cp.getConnection();
    Preondition Violations
    Unmatched statement c=cp.getConnection(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    22
    c = cp.getConnection();
    22
    time = System.currentTimeMillis();
    23
    time = System.currentTimeMillis();
                                                                              
    24
    directJDBC(c, simples, ids, n, "j2");
    Preondition Violations
    Unmatched statement directJDBC(c,simples,ids,n,"j2"); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    24
    directJDBC(c, simples, ids, n, "j2");
    23
    hibernate(s, simples, ids, n, "h2");
    23
    hibernate(s, simples, ids, n, "h2");
    26
    cp.closeConnection(c);
    Differences
    Expression1Expression2Difference
    hibernatecloseConnectionMETHOD_INVOCATION_NAME_MISMATCH
    hibernate(s,simples,ids,n,"h2")cp.closeConnection(c)ARGUMENT_NUMBER_MISMATCH
    cpMISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression hibernate(s,simples,ids,n,"h2") cannot be parameterized, because it has dependencies to/from statements that will be extracted
    • Inline private method hibernate
    Expression hibernate(s,simples,ids,n,"h2") is a void method call, and thus it cannot be parameterized
    Expression cp.closeConnection(c) is a void method call, and thus it cannot be parameterized
    Expression hibernate(s,simples,ids,n,"h2") cannot be parameterized, because it has dependencies to/from statements that will be extracted
    • Inline private method hibernate
    Expression hibernate(s,simples,ids,n,"h2") is a void method call, and thus it cannot be parameterized
    Expression cp.closeConnection(c) is a void method call, and thus it cannot be parameterized
    26
    cp.closeConnection(c);
    24
    hiber += System.currentTimeMillis() - time;
    24
    hiber += System.currentTimeMillis() - time;
    25
    jdbc += System.currentTimeMillis() - time;
    Differences
    Expression1Expression2Difference
    hiberjdbcVARIABLE_NAME_MISMATCH
    25
    jdbc += System.currentTimeMillis() - time;
    25
    s.close();
                                
    26
    s = openSession();
    26
    s = openSession();
    Preondition Violations
    Unmatched statement s=openSession(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                            
                                                      
    27
    c = cp.getConnection();
    Preondition Violations
    Unmatched statement c=cp.getConnection(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    27
    c = cp.getConnection();
    27
    time = System.currentTimeMillis();
    28
    time = System.currentTimeMillis();
                                                                              
    29
    directJDBC(c, simples, ids, n, "j2");
    Preondition Violations
    Unmatched statement directJDBC(c,simples,ids,n,"j2"); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    29
    directJDBC(c, simples, ids, n, "j2");
    28
    hibernate(s, simples, ids, n, "h2");
    28
    hibernate(s, simples, ids, n, "h2");
    31
    cp.closeConnection(c);
    Differences
    Expression1Expression2Difference
    hibernatecloseConnectionMETHOD_INVOCATION_NAME_MISMATCH
    hibernate(s,simples,ids,n,"h2")cp.closeConnection(c)ARGUMENT_NUMBER_MISMATCH
    cpMISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression hibernate(s,simples,ids,n,"h2") cannot be parameterized, because it has dependencies to/from statements that will be extracted
    • Inline private method hibernate
    Expression hibernate(s,simples,ids,n,"h2") is a void method call, and thus it cannot be parameterized
    Expression cp.closeConnection(c) is a void method call, and thus it cannot be parameterized
    Expression hibernate(s,simples,ids,n,"h2") cannot be parameterized, because it has dependencies to/from statements that will be extracted
    • Inline private method hibernate
    Expression hibernate(s,simples,ids,n,"h2") is a void method call, and thus it cannot be parameterized
    Expression cp.closeConnection(c) is a void method call, and thus it cannot be parameterized
    31
    cp.closeConnection(c);
    29
    hiber += System.currentTimeMillis() - time;
    29
    hiber += System.currentTimeMillis() - time;
    30
    jdbc += System.currentTimeMillis() - time;
    Differences
    Expression1Expression2Difference
    hiberjdbcVARIABLE_NAME_MISMATCH
    30
    jdbc += System.currentTimeMillis() - time;
    30
    s.close();
                                
    31
    System.out.println("Objects: " + n + " - Hibernate: " + hiber);
    31
    System.out.println("Objects: " + n + " - Hibernate: " + hiber);
    32
    System.out.println("Objects: " + n + " Direct JDBC: " + jdbc);
    Differences
    Expression1Expression2Difference
    " - Hibernate: "" Direct JDBC: "LITERAL_VALUE_MISMATCH
    hiberjdbcVARIABLE_NAME_MISMATCH
    32
    System.out.println("Objects: " + n + " Direct JDBC: " + jdbc);
    Precondition Violations (28)
    Row Violation
    1Unmatched statement s=openSession(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    2Unmatched statement Connection c=cp.getConnection(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    3Unmatched statement directJDBC(c,simples,ids,n,"j1"); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    4Expression hibernate(s,simples,ids,n,"h1") cannot be parameterized, because it has dependencies to/from statements that will be extracted
    5Expression hibernate(s,simples,ids,n,"h1") is a void method call, and thus it cannot be parameterized
    6Expression cp.closeConnection(c) is a void method call, and thus it cannot be parameterized
    7Expression hibernate(s,simples,ids,n,"h1") cannot be parameterized, because it has dependencies to/from statements that will be extracted
    8Expression hibernate(s,simples,ids,n,"h1") is a void method call, and thus it cannot be parameterized
    9Expression cp.closeConnection(c) is a void method call, and thus it cannot be parameterized
    10Unmatched statement s=openSession(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    11Unmatched statement c=cp.getConnection(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    12Unmatched statement directJDBC(c,simples,ids,n,"j2"); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    13Expression hibernate(s,simples,ids,n,"h2") cannot be parameterized, because it has dependencies to/from statements that will be extracted
    14Expression hibernate(s,simples,ids,n,"h2") is a void method call, and thus it cannot be parameterized
    15Expression cp.closeConnection(c) is a void method call, and thus it cannot be parameterized
    16Expression hibernate(s,simples,ids,n,"h2") cannot be parameterized, because it has dependencies to/from statements that will be extracted
    17Expression hibernate(s,simples,ids,n,"h2") is a void method call, and thus it cannot be parameterized
    18Expression cp.closeConnection(c) is a void method call, and thus it cannot be parameterized
    19Unmatched statement s=openSession(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    20Unmatched statement c=cp.getConnection(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    21Unmatched statement directJDBC(c,simples,ids,n,"j2"); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    22Expression hibernate(s,simples,ids,n,"h2") cannot be parameterized, because it has dependencies to/from statements that will be extracted
    23Expression hibernate(s,simples,ids,n,"h2") is a void method call, and thus it cannot be parameterized
    24Expression cp.closeConnection(c) is a void method call, and thus it cannot be parameterized
    25Expression hibernate(s,simples,ids,n,"h2") cannot be parameterized, because it has dependencies to/from statements that will be extracted
    26Expression hibernate(s,simples,ids,n,"h2") is a void method call, and thus it cannot be parameterized
    27Expression cp.closeConnection(c) is a void method call, and thus it cannot be parameterized
    28Clone fragment #1 returns variables s , while Clone fragment #2 returns variables simples, ids