KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > scriptella > util > ColumnsMapPerfTest


1 /*
2  * Copyright 2006-2007 The Scriptella Project Team.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package scriptella.util;
17
18 import scriptella.AbstractTestCase;
19
20 /**
21  * Performance test for {@link ColumnsMap}.
22  *
23  * @author Fyodor Kupolov
24  * @version 1.0
25  */

26 public class ColumnsMapPerfTest extends AbstractTestCase {
27     private ColumnsMap cm;
28     private static final int SEARCH_LOOP_COUNT = 300000;
29     private static final String JavaDoc[] colNames=new String JavaDoc[400];
30     private static final String JavaDoc[] colIndeces=new String JavaDoc[colNames.length];
31     static {
32         for (int i=0;i<colNames.length;i++) {
33             colNames[i]="col"+i;
34             colIndeces[i]=String.valueOf(i);
35         }
36     }
37
38     protected void setUp() throws Exception JavaDoc {
39         super.setUp();
40         cm=new ColumnsMap();
41         for (int i=1;i<200;i++) {
42             cm.registerColumn(colNames[i].toUpperCase(),i);
43         }
44     }
45
46     /**
47      * History:
48      * 06.09.2006 - Duron 1.7Mhz - 1046 ms
49      * 11.09.2006 - Duron 1.7Mhz - 422 ms
50      */

51     public void testNamedSearch() {
52         for (int i=1;i<SEARCH_LOOP_COUNT;i++) {
53             cm.find(colNames[i%250]); //20% misses
54
}
55     }
56
57     /**
58      * History:
59      * 06.09.2006 - Duron 1.7Mhz - 563 ms
60      * 11.09.2006 - Duron 1.7Mhz - 25 ms
61      */

62     public void testIndexedSearch() {
63         for (int i=1;i<SEARCH_LOOP_COUNT;i++) {
64             cm.find(colIndeces[i%250]); //20% misses
65
}
66     }
67
68
69     /**
70      * History:
71      * 06.09.2006 - Duron 1.7Mhz - 891 ms
72      * 11.09.2006 - Duron 1.7Mhz - 359 ms
73      */

74     public void testFill() {
75         for (int k=1;k<700;k++) {
76             for (int i=1;i<colNames.length;i++) {
77                 cm.registerColumn(colNames[i],i);
78             }
79         }
80     }
81 }
82
Popular Tags