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 s = openSession(); long time = System.currentTimeMillis(); hibernate(s, simples, ids, n, "h1"); long hiber = System.currentTimeMillis() - time; s.close(); c = cp.getConnection(); time = System.currentTimeMillis(); directJDBC( c, simples, ids, n, "j1" ); long jdbc = System.currentTimeMillis() - time; cp.closeConnection(c); s = openSession(); time = System.currentTimeMillis(); hibernate(s, simples, ids, n, "h2"); hiber += System.currentTimeMillis() - time; s.close(); c = cp.getConnection(); time = System.currentTimeMillis(); directJDBC( c, simples, ids, n, "j2" ); jdbc += System.currentTimeMillis() - time; cp.closeConnection(c); s = openSession(); time = System.currentTimeMillis(); hibernate(s, simples, ids, n, "h2"); hiber += System.currentTimeMillis() - time; s.close(); c = cp.getConnection(); time = System.currentTimeMillis(); directJDBC( c, simples, ids, n, "j2" ); jdbc += System.currentTimeMillis() - time; cp.closeConnection(c); System.out.println( "Objects: " + n + " - Hibernate: " + hiber + "ms / Direct JDBC: " + jdbc + "ms = Ratio: " + ( (float) hiber )/jdbc );
ConnectionProvider cp = ConnectionProviderFactory.newConnectionProvider( Environment.getProperties() ); 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); } //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 s = openSession(); long time = System.currentTimeMillis(); hibernate(s, simples, ids, n, "h1"); long hiber = System.currentTimeMillis() - time; s.close(); c = cp.getConnection(); time = System.currentTimeMillis(); directJDBC( c, simples, ids, n, "j1" ); long jdbc = System.currentTimeMillis() - time; cp.closeConnection(c); s = openSession(); time = System.currentTimeMillis(); hibernate(s, simples, ids, n, "h2"); hiber += System.currentTimeMillis() - time; s.close(); c = cp.getConnection(); time = System.currentTimeMillis(); directJDBC( c, simples, ids, n, "j2" ); jdbc += System.currentTimeMillis() - time; cp.closeConnection(c); s = openSession(); time = System.currentTimeMillis(); hibernate(s, simples, ids, n, "h2"); hiber += System.currentTimeMillis() - time; s.close(); c = cp.getConnection(); time = System.currentTimeMillis(); directJDBC( c, simples, ids, n, "j2" ); jdbc += System.currentTimeMillis() - time; cp.closeConnection(c); System.out.println( "Objects: " + n + " - 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 testSimultaneous() Method name: void testSimultaneous()
Number of AST nodes: 57 Number of AST nodes: 54
1
Session s = openSession();
2
			s.delete("from Simple");
1
ConnectionProvider cp = ConnectionProviderFactory.newConnectionProvider( Environment.getProperties() );
3
			s.flush();
2
		for ( int n=2; n<4000; n*=2 ) {
4
			Simple[] simples = new Simple[n];
3
			Simple[] simples = new Simple[n];
5
			Serializable[] ids = new Serializable[n];
4
			Serializable[] ids = new Serializable[n];
6
			for ( int i=0; i<n; i++ ) {
5
			for ( int i=0; i<n; i++ ) {
7
				simples[i] = new Simple();
6
				simples[i] = new Simple();
8
				simples[i].init();
7
				simples[i].init();
9
				simples[i].setCount(i);
8
				simples[i].setCount(i);
10
				ids[i] = new Long(i);
9
				ids[i] = new Long(i);
11
				s.save(simples[i], ids[i]);
10
			
12
			}
13
			s.flush();
14
			s.connection().commit();
15
			s.close();
11
}
16
			//allow cache to settle
12
			//allow cache to settle
17
			s = openSession();
13
			Session s = openSession();
18
			hibernate(s, simples, ids, n, "h0");
14
			hibernate(s, simples, ids, n, "h0");
19
			s.close();
15
			s.close();
20
			Connection c = cp.getConnection();
16
			Connection c = cp.getConnection();
21
			directJDBC( c, simples, ids, n, "j0" );
17
			directJDBC( c, simples, ids, n, "j0" );
22
			cp.closeConnection(c);
18
			cp.closeConnection(c);
23
			s = openSession();
19
			s = openSession();
24
			hibernate(s, simples, ids, n, "h0");
20
			hibernate(s, simples, ids, n, "h0");
25
			s.close();
21
			s.close();
26
			c = cp.getConnection();
22
			c = cp.getConnection();
27
			directJDBC( c, simples, ids, n, "j0" );
23
			directJDBC( c, simples, ids, n, "j0" );
28
			cp.closeConnection(c);
24
			cp.closeConnection(c);
29
			//Now do timings
25
			//Now do timings
30
			s = openSession();
26
			s = openSession();
31
			long time = System.currentTimeMillis();
27
			long time = System.currentTimeMillis();
32
			hibernate(s, simples, ids, n, "h1");
28
			hibernate(s, simples, ids, n, "h1");
33
			long hiber = System.currentTimeMillis() - time;
29
			long hiber = System.currentTimeMillis() - time;
34
			s.close();
30
			s.close();
35
			c = cp.getConnection();
31
			c = cp.getConnection();
36
			time = System.currentTimeMillis();
32
			time = System.currentTimeMillis();
37
			directJDBC( c, simples, ids, n, "j1" );
33
			directJDBC( c, simples, ids, n, "j1" );
38
			long jdbc = System.currentTimeMillis() - time;
34
			long jdbc = System.currentTimeMillis() - time;
39
			cp.closeConnection(c);
35
			cp.closeConnection(c);
40
			s = openSession();
36
			s = openSession();
41
			time = System.currentTimeMillis();
37
			time = System.currentTimeMillis();
42
			hibernate(s, simples, ids, n, "h2");
38
			hibernate(s, simples, ids, n, "h2");
43
			hiber += System.currentTimeMillis() - time;
39
			hiber += System.currentTimeMillis() - time;
44
			s.close();
40
			s.close();
45
			c = cp.getConnection();
41
			c = cp.getConnection();
46
			time = System.currentTimeMillis();
42
			time = System.currentTimeMillis();
47
			directJDBC( c, simples, ids, n, "j2" );
43
			directJDBC( c, simples, ids, n, "j2" );
48
			jdbc += System.currentTimeMillis() - time;
44
			jdbc += System.currentTimeMillis() - time;
49
			cp.closeConnection(c);
45
			cp.closeConnection(c);
50
			s = openSession();
46
			s = openSession();
51
			time = System.currentTimeMillis();
47
			time = System.currentTimeMillis();
52
			hibernate(s, simples, ids, n, "h2");
48
			hibernate(s, simples, ids, n, "h2");
53
			hiber += System.currentTimeMillis() - time;
49
			hiber += System.currentTimeMillis() - time;
54
			s.close();
50
			s.close();
55
			c = cp.getConnection();
51
			c = cp.getConnection();
56
			time = System.currentTimeMillis();
52
			time = System.currentTimeMillis();
57
			directJDBC( c, simples, ids, n, "j2" );
53
			directJDBC( c, simples, ids, n, "j2" );
58
			jdbc += System.currentTimeMillis() - time;
54
			jdbc += System.currentTimeMillis() - time;
59
			cp.closeConnection(c);
55
			cp.closeConnection(c);
60
			System.out.println( "Objects: " + n + " - Hibernate: " + hiber + "ms / Direct JDBC: " + jdbc + "ms = Ratio: " + ( (float) hiber )/jdbc );
56
			System.out.println( "Objects: " + n + " - Hibernate: " + hiber + "ms / Direct JDBC: " + jdbc + "ms = Ratio: " + ( (float) hiber )/jdbc );
57
		}
58
		cp.close();
59
		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)0.4
Clones locationClones are in different classes having the same super class
Number of node comparisons319
  1. {Non-refactorable}
    Mapping Summary
    Number of mapped statements50
    Number of unmapped statements in the first code fragment7
    Number of unmapped statements in the second code fragment0
    Time elapsed for statement mapping (ms)114.9
    Clone typeType 3
    Mapped Statements
    ID Statement ID Statement
    3
    Session s = openSession();
    10
    Session s = openSession();
    4
    s.delete("from Simple");
    4
    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
                                                          
    5
    s.flush();
    5
    s.flush();
    Preondition Violations
    Unmatched statement s.flush(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                              
    6
    Simple[] simples = new Simple[n];
    3
    Simple[] simples = new Simple[n];
    7
    Serializable[] ids = new Serializable[n];
    4
    Serializable[] ids = new Serializable[n];
    8
    for (int i = 0; i < n; i++)
    5
    for (int i = 0; i < n; i++)
    9
    simples[i] = new Simple();
    6
    simples[i] = new Simple();
    10
    simples[i].init();
    7
    simples[i].init();
    11
    simples[i].setCount(i);
    8
    simples[i].setCount(i);
    12
    ids[i] = new Long(i);
    9
    ids[i] = new Long(i);
    13
    s.save(simples[i], ids[i]);
    13
    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
    Unmatched statement s.save(simples[i],ids[i]); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted
                                                                
    14
    s.flush();
    14
    s.flush();
    Preondition Violations
    Unmatched statement s.flush(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                
    15
    s.connection().commit();
    15
    s.connection().commit();
    Preondition Violations
    Unmatched statement s.connection().commit(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
                                                            
    16
    s.close();
    12
    s.close();
    17
    s = openSession();
    16
    s = openSession();
    18
    hibernate(s, simples, ids, n, "h0");
    17
    hibernate(s, simples, ids, n, "h0");
    19
    s.close();
    18
    s.close();
    20
    Connection c = cp.getConnection();
    13
    Connection c = cp.getConnection();
    21
    directJDBC(c, simples, ids, n, "j0");
    20
    directJDBC(c, simples, ids, n, "j0");
    22
    cp.closeConnection(c);
    21
    cp.closeConnection(c);
    23
    s = openSession();
    22
    s = openSession();
    24
    hibernate(s, simples, ids, n, "h0");
    11
    hibernate(s, simples, ids, n, "h0");
    25
    s.close();
    26
    s.close();
    26
    c = cp.getConnection();
    27
    c = cp.getConnection();
    27
    directJDBC(c, simples, ids, n, "j0");
    14
    directJDBC(c, simples, ids, n, "j0");
    28
    cp.closeConnection(c);
    31
    cp.closeConnection(c);
    29
    s = openSession();
    32
    s = openSession();
    30
    long time = System.currentTimeMillis();
    23
    long time = System.currentTimeMillis();
    31
    hibernate(s, simples, ids, n, "h1");
    24
    hibernate(s, simples, ids, n, "h1");
    32
    long hiber = System.currentTimeMillis() - time;
    25
    long hiber = System.currentTimeMillis() - time;
    33
    s.close();
    36
    s.close();
    34
    c = cp.getConnection();
    37
    c = cp.getConnection();
    35
    time = System.currentTimeMillis();
    33
    time = System.currentTimeMillis();
    36
    directJDBC(c, simples, ids, n, "j1");
    29
    directJDBC(c, simples, ids, n, "j1");
    37
    long jdbc = System.currentTimeMillis() - time;
    30
    long jdbc = System.currentTimeMillis() - time;
    38
    cp.closeConnection(c);
    41
    cp.closeConnection(c);
    39
    s = openSession();
    42
    s = openSession();
    40
    time = System.currentTimeMillis();
    38
    time = System.currentTimeMillis();
    41
    hibernate(s, simples, ids, n, "h2");
    44
    hibernate(s, simples, ids, n, "h2");
    42
    hiber += System.currentTimeMillis() - time;
    45
    hiber += System.currentTimeMillis() - time;
    43
    s.close();
    46
    s.close();
    44
    c = cp.getConnection();
    47
    c = cp.getConnection();
    45
    time = System.currentTimeMillis();
    43
    time = System.currentTimeMillis();
    46
    directJDBC(c, simples, ids, n, "j2");
    49
    directJDBC(c, simples, ids, n, "j2");
    47
    jdbc += System.currentTimeMillis() - time;
    50
    jdbc += System.currentTimeMillis() - time;
    48
    cp.closeConnection(c);
    51
    cp.closeConnection(c);
    49
    s = openSession();
    49
    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
                                            
    50
    time = System.currentTimeMillis();
    48
    time = System.currentTimeMillis();
    51
    hibernate(s, simples, ids, n, "h2");
    34
    hibernate(s, simples, ids, n, "h2");
    52
    hiber += System.currentTimeMillis() - time;
    35
    hiber += System.currentTimeMillis() - time;
    53
    s.close();
                                
    54
    c = cp.getConnection();
    19
    c = cp.getConnection();
    55
    time = System.currentTimeMillis();
    28
    time = System.currentTimeMillis();
    56
    directJDBC(c, simples, ids, n, "j2");
    39
    directJDBC(c, simples, ids, n, "j2");
    57
    jdbc += System.currentTimeMillis() - time;
    40
    jdbc += System.currentTimeMillis() - time;
    58
    cp.closeConnection(c);
    15
    cp.closeConnection(c);
    59
    System.out.println("Objects: " + n + " - Hibernate: " + hiber + "ms / Direct JDBC: " + jdbc + "ms = Ratio: " + ((float)hiber) / jdbc);
    52
    System.out.println("Objects: " + n + " - Hibernate: " + hiber + "ms / Direct JDBC: " + jdbc + "ms = Ratio: " + ((float)hiber) / jdbc);
    Precondition Violations (8)
    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.flush(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    3Unmatched 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
    4Unmatched statement s.save(simples[i],ids[i]); cannot be moved before or after the extracted code, because it throws exception(s) that should be caught by a try block that will be extracted
    5Unmatched statement s.flush(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    6Unmatched statement s.connection().commit(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    7Unmatched statement s=openSession(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted
    8Clone fragment #1 returns variables s , while Clone fragment #2 returns variables