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 |
| |||
See real code fragment | See real code fragment |
Number of common nesting structure subtrees | 1 |
Number of refactorable cases | 0 |
Number of non-refactorable cases | 1 |
Time elapsed for finding largest common nesting structure subtrees (ms) | 5.1 |
Clones location | Clones are in different classes having the same super class |
Number of node comparisons | 1497 |
Number of mapped statements | 57 |
Number of unmapped statements in the first code fragment | 7 |
Number of unmapped statements in the second code fragment | 6 |
Time elapsed for statement mapping (ms) | 1563.2 |
Clone type | Type 3 |
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"); |
| | |||||
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]); |
| | |||||
16 | s.flush(); |
| | |||||
17 | s.connection().commit(); |
| | |||||
18 | s.close(); | 14 | s.close(); | |||||
19 | s = openSession(); |
| | |||||
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"); | 22 | directJDBC(c, simples, ids, n, "j0"); | |||||
24 | cp.closeConnection(c); | 17 | 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"); | 16 | directJDBC(c, simples, ids, n, "j0"); | |||||
30 | cp.closeConnection(c); | 23 | cp.closeConnection(c); | |||||
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(); |
Row | Violation |
---|---|
1 | 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 |
2 | Unmatched statement s.delete("from Simple"); 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 |
3 | Unmatched statement s.flush(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
4 | Unmatched statement s.flush(); 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 |
5 | 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 |
6 | 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 |
7 | Unmatched statement s.flush(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
8 | Unmatched statement s.flush(); 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 |
9 | 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 |
10 | Unmatched statement s.connection().commit(); 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 |
11 | Unmatched statement s=openSession(); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
12 | Unmatched statement s=openSession(); 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 |
13 | Unmatched statement s.close(); 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 | Unmatched statement System.out.println("Hibernate: " + hiber + "ms / Direct JDBC: "+ jdbc+ "ms = Ratio: "+ ((float)hiber) / jdbc); cannot be moved before or after the extracted code, because it has dependencies to/from statements that will be extracted |
15 | Clone fragment #1 returns variables s, hiber, jdbc , while Clone fragment #2 returns variables |