KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > ozoneDB > DxLib > SimpleTest


1 // You can redistribute this software and/or modify it under the terms of
2
// the Ozone Library License version 1 published by ozone-db.org.
3
//
4
// The original code and portions created by SMB are
5
// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
6
//
7
// $Id$
8

9 package test.ozoneDB.DxLib;
10
11 import org.ozoneDB.DxLib.*;
12
13
14 class SimpleTest {
15
16
17     public static void main(String JavaDoc[] args) throws Exception JavaDoc {
18         DxDeque deque = new DxArrayDeque(1024);
19         deque.peek();
20         deque.pushBottom("daniela");
21         deque.pushBottom("knuffi");
22
23         System.out.println(deque.count());
24         System.out.println(deque.popBottom());
25         System.out.println(deque.popBottom());
26
27         deque.push("daniela");
28         deque.push("knuffi");
29         System.out.println(deque.pop());
30         deque.push("mumpi");
31
32         System.out.println(deque.count());
33         System.out.println(deque.pop());
34         System.out.println(deque.pop());
35
36
37         // System.out.println ("\nzeit: " + (System.currentTimeMillis() - start) + "msec");
38
}
39
40
41     public void testMemory() {
42         Runtime JavaDoc rt = Runtime.getRuntime();
43
44         try {
45             DxVector bag = new DxArrayBag();
46             for (int i = 0; i < 100000; i++) {
47                 bag.add(new byte[100000]);
48                 System.out.println("total:" + rt.totalMemory() + " free:" + rt.freeMemory());
49             }
50         } catch (OutOfMemoryError JavaDoc e) {
51             System.gc();
52         }
53
54         System.out.println("total:" + rt.totalMemory() + " free:" + rt.freeMemory());
55     }
56
57
58     public static void testDiskHash(String JavaDoc[] args) throws Exception JavaDoc {
59         long start = System.currentTimeMillis();
60
61         int count = Integer.valueOf(args[0]).intValue();
62         boolean re_use = Boolean.valueOf(args[1]).booleanValue();
63         System.out.println(count + ", " + re_use);
64
65         DxDiskHashMap map = new DxDiskHashMap("map/map", 100, 12, 8);
66
67         // if (re_use)
68
// map.re_use();
69
// else {
70
// for (int i=0; i<count; i++) {
71
// map.addForKey ("daniela", new Integer(i));
72
// }
73
// System.out.println ("\naddForKey(): " + (System.currentTimeMillis() - start) + "msec");
74
// }
75

76         for (; ;) {
77             start = System.currentTimeMillis();
78             for (int i = 0; i < count; i++) {
79                 map.addForKey(String.valueOf(i), new Integer JavaDoc(i));
80             }
81             System.out.println("\naddForKey(): " + (System.currentTimeMillis() - start) + "msec");
82
83             start = System.currentTimeMillis();
84             for (int i = 0; i < count; i++) {
85                 String JavaDoc s = (String JavaDoc) map.elementForKey(new Integer JavaDoc(i));
86                 if (!s.equals(String.valueOf(i))) {
87                     throw new Exception JavaDoc("falscher inhalt");
88                 }
89             }
90             System.out.println("\nelementForKey(): " + (System.currentTimeMillis() - start) + "msec");
91
92             start = System.currentTimeMillis();
93             for (int i = 0; i < count; i++) {
94                 String JavaDoc s = (String JavaDoc) map.removeForKey(new Integer JavaDoc(i));
95                 if (!s.equals(String.valueOf(i))) {
96                     throw new Exception JavaDoc("falscher inhalt");
97                 }
98             }
99             System.out.println("\nremoveForKey(): " + (System.currentTimeMillis() - start) + "msec");
100
101             map.printStatistics();
102         }
103
104         // map.close();
105
// System.out.println ("\nclose(): " + (System.currentTimeMillis() - start) + "msec");
106
}
107
108 }
109
Popular Tags