01: package jdbm.btree;
02:
03: import java.io.IOException;
04: import java.util.Properties;
05:
06: import jdbm.RecordManager;
07: import jdbm.RecordManagerFactory;
08: import jdbm.btree.BTree;
09: import jdbm.helper.LongComparator;
10:
11: /**
12: * Test BTree insert performance.
13: */
14: public class TestInsertPerf {
15:
16: int _numberOfObjects;
17:
18: public TestInsertPerf(int numberOfObjects) {
19: _numberOfObjects = numberOfObjects;
20: }
21:
22: public void insert() throws IOException {
23:
24: BTree btree;
25: RecordManager recman;
26: long start, finish;
27: Properties props;
28:
29: props = new Properties();
30: recman = RecordManagerFactory.createRecordManager(
31: "TestInsertPref-" + System.currentTimeMillis(), props);
32: btree = BTree.createInstance(recman, new LongComparator());
33:
34: // Note: One can use specialized serializers for better performance / database size
35: // btree = BTree.createInstance( recman, new LongComparator(),
36: // LongSerializer.INSTANCE, IntegerSerializer.INSTANCE );
37:
38: start = System.currentTimeMillis();
39: for (int i = 0; i < _numberOfObjects; i++) {
40: btree.insert(new Long(i), new Integer(i), false);
41: }
42: recman.commit();
43: finish = System.currentTimeMillis();
44:
45: System.out.println("It took " + (finish - start)
46: + " ms to insert " + _numberOfObjects + " objects.");
47:
48: }
49:
50: public static void main(String[] args) {
51: if (args.length != 1) {
52: System.out
53: .println("Usage: TestInsertPerf [numberOfObjects]");
54: return;
55: }
56: int numberOfObjects = Integer.parseInt(args[0]);
57: TestInsertPerf test = new TestInsertPerf(numberOfObjects);
58: try {
59: test.insert();
60: } catch (IOException except) {
61: except.printStackTrace();
62: }
63: }
64:
65: }
|