for ( int n=0; n<20; n++ ) { Session s = openSession(); s.delete("from Simple"); s.flush(); 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); s.save(simples[i], ids[i]); } s.flush(); s.connection().commit(); s.close(); //allow cache to settle s = openSession(); hibernate(s, simples, ids, n, "h0"); s.close(); Connection c = cp.getConnection(); directJDBC( c, simples, ids, n, "j0" ); cp.closeConnection(c); s = openSession(); hibernate(s, simples, ids, n, "h0"); s.close(); c = cp.getConnection(); directJDBC( c, simples, ids, n, "j0" ); cp.closeConnection(c); //Now do timings int N=30; long time = System.currentTimeMillis(); for (int i=0; i<N; i++) { s = openSession(); hibernate(s, simples, ids, n, "h1"); s.close(); } hiber += System.currentTimeMillis() - time; time = System.currentTimeMillis(); for (int i=0; i<N; i++) { c = cp.getConnection(); directJDBC( c, simples, ids, n, "j1" ); cp.closeConnection(c); } jdbc += System.currentTimeMillis() - time; time = System.currentTimeMillis(); for (int i=0; i<N; i++) { s = openSession(); hibernate(s, simples, ids, n, "h2"); s.close(); } hiber += System.currentTimeMillis() - time; time = System.currentTimeMillis(); for (int i=0; i<N; i++) { c = cp.getConnection(); directJDBC( c, simples, ids, n, "j2" ); cp.closeConnection(c); } jdbc += System.currentTimeMillis() - time; time = System.currentTimeMillis(); for (int i=0; i<N; i++) { s = openSession(); hibernate(s, simples, ids, n, "h1"); s.close(); } hiber += System.currentTimeMillis() - time; time = System.currentTimeMillis(); for (int i=0; i<N; i++) { c = cp.getConnection(); directJDBC( c, simples, ids, n, "j1" ); cp.closeConnection(c); } jdbc += System.currentTimeMillis() - time; }
ConnectionProvider cp = ConnectionProviderFactory.newConnectionProvider( Environment.getProperties() ); long hiber=0; long jdbc=0; for ( int n=0; n<20; n++ ) { 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); } //allow cache to settle Session s = openSession(); hibernate(s, simples, ids, n, "h0"); s.close(); Connection c = cp.getConnection(); directJDBC( c, simples, ids, n, "j0" ); cp.closeConnection(c); s = openSession(); hibernate(s, simples, ids, n, "h0"); s.close(); c = cp.getConnection(); directJDBC( c, simples, ids, n, "j0" ); cp.closeConnection(c); //Now do timings int N=30; long time = System.currentTimeMillis(); for (int i=0; i<N; i++) { s = openSession(); hibernate(s, simples, ids, n, "h1"); s.close(); } hiber += System.currentTimeMillis() - time; time = System.currentTimeMillis(); for (int i=0; i<N; i++) { c = cp.getConnection(); directJDBC( c, simples, ids, n, "j1" ); cp.closeConnection(c); } jdbc += System.currentTimeMillis() - time; time = System.currentTimeMillis(); for (int i=0; i<N; i++) { s = openSession(); hibernate(s, simples, ids, n, "h2"); s.close(); } hiber += System.currentTimeMillis() - time; time = System.currentTimeMillis(); for (int i=0; i<N; i++) { c = cp.getConnection(); directJDBC( c, simples, ids, n, "j2" ); cp.closeConnection(c); } jdbc += System.currentTimeMillis() - time; time = System.currentTimeMillis(); for (int i=0; i<N; i++) { s = openSession(); hibernate(s, simples, ids, n, "h1"); s.close(); } hiber += System.currentTimeMillis() - time; time = System.currentTimeMillis(); for (int i=0; i<N; i++) { c = cp.getConnection(); directJDBC( c, simples, ids, n, "j1" ); cp.closeConnection(c); } jdbc += System.currentTimeMillis() - time; } System.out.println( "Hibernate: " + hiber + "ms / Direct JDBC: " + jdbc + "ms = Ratio: " + ( (float) hiber )/jdbc ); cp.close(); System.gc();
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/PerformanceTest.java
Method name: void testMany() Method name: void testMany()
Number of AST nodes: 64 Number of AST nodes: 63
1
for ( int n=0; n<20; n++ ) {
2
			Session s = openSession();
1
ConnectionProvider cp = ConnectionProviderFactory.newConnectionProvider( Environment.getProperties() );
3
	
4
		s.delete("from Simple");
2
		
5
			s.flush();
3
long hiber=0;
4
		long jdbc=0;
5
		for ( int n=0; n<20; n++ ) {
6
			Simple[] simples = new Simple[n];
6
			Simple[] simples = new Simple[n];
7
			Serializable[] ids = new Serializable[n];
7
			Serializable[] ids = new Serializable[n];
8
			for ( int i=0; i<n; i++ ) {
8
			for ( int i=0; i<n; i++ ) {
9
				simples[i] = new Simple();
9
				simples[i] = new Simple();
10
				simples[i].init();
10
				simples[i].init();
11
				simples[i].setCount(i);
11
				simples[i].setCount(i);
12
				ids[i] = new Long(i);
12
				ids[i] = new Long(i);
13
				s.save(simples[i], ids[i]);
13
			
14
			}
15
			s.flush();
16
			s.connection().commit();
17
			s.close();
14
}
18
			//allow cache to settle
15
			//allow cache to settle
19
			s = openSession();
16
			Session s = openSession();
20
			hibernate(s, simples, ids, n, "h0");
17
			hibernate(s, simples, ids, n, "h0");
21
			s.close();
18
			s.close();
22
			Connection c = cp.getConnection();
19
			Connection c = cp.getConnection();
23
			directJDBC( c, simples, ids, n, "j0" );
20
			directJDBC( c, simples, ids, n, "j0" );
24
			cp.closeConnection(c);
21
			cp.closeConnection(c);
25
			s = openSession();
22
			s = openSession();
26
			hibernate(s, simples, ids, n, "h0");
23
			hibernate(s, simples, ids, n, "h0");
27
			s.close();
24
			s.close();
28
			c = cp.getConnection();
25
			c = cp.getConnection();
29
			directJDBC( c, simples, ids, n, "j0" );
26
			directJDBC( c, simples, ids, n, "j0" );
30
			cp.closeConnection(c);
27
			cp.closeConnection(c);
31
			//Now do timings
28
			//Now do timings
32
			int N=30;
29
			int N=30;
33
			long time = System.currentTimeMillis();
30
			long time = System.currentTimeMillis();
34
			for (int i=0; i<N; i++) {
31
			for (int i=0; i<N; i++) {
35
				s = openSession();
32
				s = openSession();
36
				hibernate(s, simples, ids, n, "h1");
33
				hibernate(s, simples, ids, n, "h1");
37
				s.close();
34
				s.close();
38
			}
35
			}
39
			hiber += System.currentTimeMillis() - time;
36
			hiber += System.currentTimeMillis() - time;
40
			time = System.currentTimeMillis();
37
			time = System.currentTimeMillis();
41
			for (int i=0; i<N; i++) {
38
			for (int i=0; i<N; i++) {
42
				c = cp.getConnection();
39
				c = cp.getConnection();
43
				directJDBC( c, simples, ids, n, "j1" );
40
				directJDBC( c, simples, ids, n, "j1" );
44
				cp.closeConnection(c);
41
				cp.closeConnection(c);
45
			}
42
			}
46
			jdbc += System.currentTimeMillis() - time;
43
			jdbc += System.currentTimeMillis() - time;
47
			time = System.currentTimeMillis();
44
			time = System.currentTimeMillis();
48
			for (int i=0; i<N; i++) {
45
			for (int i=0; i<N; i++) {
49
				s = openSession();
46
				s = openSession();
50
				hibernate(s, simples, ids, n, "h2");
47
				hibernate(s, simples, ids, n, "h2");
51
				s.close();
48
				s.close();
52
			}
49
			}
53
			hiber += System.currentTimeMillis() - time;
50
			hiber += System.currentTimeMillis() - time;
54
			time = System.currentTimeMillis();
51
			time = System.currentTimeMillis();
55
			for (int i=0; i<N; i++) {
52
			for (int i=0; i<N; i++) {
56
				c = cp.getConnection();
53
				c = cp.getConnection();
57
				directJDBC( c, simples, ids, n, "j2" );
54
				directJDBC( c, simples, ids, n, "j2" );
58
				cp.closeConnection(c);
55
				cp.closeConnection(c);
59
			}
56
			}
60
			jdbc += System.currentTimeMillis() - time;
57
			jdbc += System.currentTimeMillis() - time;
61
			time = System.currentTimeMillis();
58
			time = System.currentTimeMillis();
62
			for (int i=0; i<N; i++) {
59
			for (int i=0; i<N; i++) {
63
				s = openSession();
60
				s = openSession();
64
				hibernate(s, simples, ids, n, "h1");
61
				hibernate(s, simples, ids, n, "h1");
65
				s.close();
62
				s.close();
66
			}
63
			}
67
			hiber += System.currentTimeMillis() - time;
64
			hiber += System.currentTimeMillis() - time;
68
			time = System.currentTimeMillis();
65
			time = System.currentTimeMillis();
69
			for (int i=0; i<N; i++) {
66
			for (int i=0; i<N; i++) {
70
				c = cp.getConnection();
67
				c = cp.getConnection();
71
				directJDBC( c, simples, ids, n, "j1" );
68
				directJDBC( c, simples, ids, n, "j1" );
72
				cp.closeConnection(c);
69
				cp.closeConnection(c);
73
			}
70
			}
74
			jdbc += System.currentTimeMillis() - time;
71
			jdbc += System.currentTimeMillis() - time;
75
		}
72
		}
73
		System.out.println( "Hibernate: " + hiber + "ms / Direct JDBC: " + jdbc + "ms = Ratio: " + ( (float) hiber )/jdbc );
74
		cp.close();
75
		System.gc();
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)7.6
Clones locationClones are in different classes having the same super class
Number of node comparisons1497
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements57
    Number of unmapped statements in the first code fragment7
    Number of unmapped statements in the second code fragment6
    Time elapsed for statement mapping (ms)182.0
    Clone typeType 3
    Mapped Statements
    ID Statement ID Statement
                                                                                                                                                                                                                
    1
    ConnectionProvider cp = ConnectionProviderFactory.newConnectionProvider(Environment.getProperties());
                                    
    2
    long hiber = 0;
                                  
    3
    long jdbc = 0;
    4
    for (int n = 0; n < 20; n++)
    4
    for (int n = 0; n < 20; n++)
    5
    Session s = openSession();
    12
    Session s = openSession();
    6
    s.delete("from Simple");
    6
    s.delete("from Simple");
    Preondition Violations
    Unmatched statement s.delete("from Simple"); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                          
    7
    s.flush();
                              
    8
    Simple[] simples = new Simple[n];
    5
    Simple[] simples = new Simple[n];
    9
    Serializable[] ids = new Serializable[n];
    6
    Serializable[] ids = new Serializable[n];
    10
    for (int i = 0; i < n; i++)
    7
    for (int i = 0; i < n; i++)
    11
    simples[i] = new Simple();
    8
    simples[i] = new Simple();
    12
    simples[i].init();
    9
    simples[i].init();
    13
    simples[i].setCount(i);
    10
    simples[i].setCount(i);
    14
    ids[i] = new Long(i);
    11
    ids[i] = new Long(i);
    15
    s.save(simples[i], ids[i]);
    15
    s.save(simples[i], ids[i]);
    Preondition Violations
    Unmatched statement s.save(simples[i],ids[i]); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                                
    16
    s.flush();
    16
    s.flush();
    16
    directJDBC(c, simples, ids, n, "j0");
    Differences
    Expression1Expression2Difference
    flushdirectJDBCMETHOD_INVOCATION_NAME_MISMATCH
    s.flush()directJDBC(c,simples,ids,n,"j0")ARGUMENT_NUMBER_MISMATCH
    sMISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression s.flush() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression directJDBC(c,simples,ids,n,"j0") cannot be parameterized, because it has dependencies to/from statements that will be extracted
    • Inline private method directJDBC
    Expression s.flush() is a void method call, and thus it cannot be parameterized
    Expression directJDBC(c,simples,ids,n,"j0") is a void method call, and thus it cannot be parameterized
    Expression s.flush() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression directJDBC(c,simples,ids,n,"j0") cannot be parameterized, because it has dependencies to/from statements that will be extracted
    • Inline private method directJDBC
    Expression s.flush() is a void method call, and thus it cannot be parameterized
    Expression directJDBC(c,simples,ids,n,"j0") is a void method call, and thus it cannot be parameterized
    16
    directJDBC(c, simples, ids, n, "j0");
    17
    s.connection().commit();
                                                            
    18
    s.close();
    14
    s.close();
    19
    s = openSession();
    19
    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
                                            
    20
    hibernate(s, simples, ids, n, "h0");
    13
    hibernate(s, simples, ids, n, "h0");
    21
    s.close();
                                
    22
    Connection c = cp.getConnection();
    15
    Connection c = cp.getConnection();
    23
    directJDBC(c, simples, ids, n, "j0");
    23
    directJDBC(c, simples, ids, n, "j0");
    17
    cp.closeConnection(c);
    Differences
    Expression1Expression2Difference
    directJDBCcloseConnectionMETHOD_INVOCATION_NAME_MISMATCH
    directJDBC(c,simples,ids,n,"j0")cp.closeConnection(c)ARGUMENT_NUMBER_MISMATCH
    cpMISSING_METHOD_INVOCATION_EXPRESSION
    Preondition Violations
    Expression directJDBC(c,simples,ids,n,"j0") cannot be parameterized, because it has dependencies to/from statements that will be extracted
    • Inline private method directJDBC
    Expression cp.closeConnection(c) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression directJDBC(c,simples,ids,n,"j0") 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 directJDBC(c,simples,ids,n,"j0") cannot be parameterized, because it has dependencies to/from statements that will be extracted
    • Inline private method directJDBC
    Expression cp.closeConnection(c) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    Expression directJDBC(c,simples,ids,n,"j0") 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
    17
    cp.closeConnection(c);
    24
    cp.closeConnection(c);
    23
    cp.closeConnection(c);
    25
    s = openSession();
    18
    s = openSession();
    26
    hibernate(s, simples, ids, n, "h0");
    19
    hibernate(s, simples, ids, n, "h0");
    27
    s.close();
    20
    s.close();
    28
    c = cp.getConnection();
    21
    c = cp.getConnection();
    29
    directJDBC(c, simples, ids, n, "j0");
    22
    directJDBC(c, simples, ids, n, "j0");
    30
    cp.closeConnection(c);
    30
    cp.closeConnection(c);
    Preondition Violations
    Unmatched statement cp.closeConnection(c); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                        
    31
    int N = 30;
    24
    int N = 30;
    32
    long time = System.currentTimeMillis();
    25
    long time = System.currentTimeMillis();
    33
    for (int i = 0; i < N; i++)
    26
    for (int i = 0; i < N; i++)
    34
    s = openSession();
    27
    s = openSession();
    35
    hibernate(s, simples, ids, n, "h1");
    28
    hibernate(s, simples, ids, n, "h1");
    36
    s.close();
    29
    s.close();
    37
    hiber += System.currentTimeMillis() - time;
    30
    hiber += System.currentTimeMillis() - time;
    38
    time = System.currentTimeMillis();
    31
    time = System.currentTimeMillis();
    39
    for (int i = 0; i < N; i++)
    32
    for (int i = 0; i < N; i++)
    40
    c = cp.getConnection();
    33
    c = cp.getConnection();
    41
    directJDBC(c, simples, ids, n, "j1");
    34
    directJDBC(c, simples, ids, n, "j1");
    42
    cp.closeConnection(c);
    35
    cp.closeConnection(c);
    43
    jdbc += System.currentTimeMillis() - time;
    36
    jdbc += System.currentTimeMillis() - time;
    44
    time = System.currentTimeMillis();
    37
    time = System.currentTimeMillis();
    45
    for (int i = 0; i < N; i++)
    38
    for (int i = 0; i < N; i++)
    46
    s = openSession();
    39
    s = openSession();
    47
    hibernate(s, simples, ids, n, "h2");
    40
    hibernate(s, simples, ids, n, "h2");
    48
    s.close();
    41
    s.close();
    49
    hiber += System.currentTimeMillis() - time;
    42
    hiber += System.currentTimeMillis() - time;
    50
    time = System.currentTimeMillis();
    43
    time = System.currentTimeMillis();
    51
    for (int i = 0; i < N; i++)
    44
    for (int i = 0; i < N; i++)
    52
    c = cp.getConnection();
    45
    c = cp.getConnection();
    53
    directJDBC(c, simples, ids, n, "j2");
    46
    directJDBC(c, simples, ids, n, "j2");
    54
    cp.closeConnection(c);
    47
    cp.closeConnection(c);
    55
    jdbc += System.currentTimeMillis() - time;
    48
    jdbc += System.currentTimeMillis() - time;
    56
    time = System.currentTimeMillis();
    49
    time = System.currentTimeMillis();
    57
    for (int i = 0; i < N; i++)
    50
    for (int i = 0; i < N; i++)
    58
    s = openSession();
    51
    s = openSession();
    59
    hibernate(s, simples, ids, n, "h1");
    52
    hibernate(s, simples, ids, n, "h1");
    60
    s.close();
    53
    s.close();
    61
    hiber += System.currentTimeMillis() - time;
    54
    hiber += System.currentTimeMillis() - time;
    62
    time = System.currentTimeMillis();
    55
    time = System.currentTimeMillis();
    63
    for (int i = 0; i < N; i++)
    56
    for (int i = 0; i < N; i++)
    64
    c = cp.getConnection();
    57
    c = cp.getConnection();
    65
    directJDBC(c, simples, ids, n, "j1");
    58
    directJDBC(c, simples, ids, n, "j1");
    66
    cp.closeConnection(c);
    59
    cp.closeConnection(c);
    67
    jdbc += System.currentTimeMillis() - time;
    60
    jdbc += System.currentTimeMillis() - time;
                                                                                                                                                                                                                                        
    61
    System.out.println("Hibernate: " + hiber + "ms / Direct JDBC: " + jdbc + "ms = Ratio: " + ((float)hiber) / jdbc);
                                  
    62
    cp.close();
                                    
    63
    System.gc();
    Precondition Violations (21)
    Row Violation
    1Unmatched statement s.delete("from Simple"); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    2Unmatched statement s.save(simples[i],ids[i]); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    3Expression s.flush() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    4Expression directJDBC(c,simples,ids,n,"j0") cannot be parameterized, because it has dependencies to/from statements that will be extracted
    5Expression s.flush() is a void method call, and thus it cannot be parameterized
    6Expression directJDBC(c,simples,ids,n,"j0") is a void method call, and thus it cannot be parameterized
    7Expression s.flush() cannot be parameterized, because it has dependencies to/from statements that will be extracted
    8Expression directJDBC(c,simples,ids,n,"j0") cannot be parameterized, because it has dependencies to/from statements that will be extracted
    9Expression s.flush() is a void method call, and thus it cannot be parameterized
    10Expression directJDBC(c,simples,ids,n,"j0") is a void method call, and thus it cannot be parameterized
    11Unmatched statement s=openSession(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    12Expression directJDBC(c,simples,ids,n,"j0") cannot be parameterized, because it has dependencies to/from statements that will be extracted
    13Expression cp.closeConnection(c) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    14Expression directJDBC(c,simples,ids,n,"j0") 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 directJDBC(c,simples,ids,n,"j0") cannot be parameterized, because it has dependencies to/from statements that will be extracted
    17Expression cp.closeConnection(c) cannot be parameterized, because it has dependencies to/from statements that will be extracted
    18Expression directJDBC(c,simples,ids,n,"j0") is a void method call, and thus it cannot be parameterized
    19Expression cp.closeConnection(c) is a void method call, and thus it cannot be parameterized
    20Unmatched statement cp.closeConnection(c); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    21Clone fragment #1 returns variables s, i, simples, ids, c, hiber, jdbc , while Clone fragment #2 returns variables hiber, jdbc