001: /*
002: This source file is part of Smyle, a database library.
003: For up-to-date information, see http://www.drjava.de/smyle
004: Copyright (C) 2001 Stefan Reich (doc@drjava.de)
005:
006: This library is free software; you can redistribute it and/or
007: modify it under the terms of the GNU Lesser General Public
008: License as published by the Free Software Foundation; either
009: version 2.1 of the License, or (at your option) any later version.
010:
011: This library is distributed in the hope that it will be useful,
012: but WITHOUT ANY WARRANTY; without even the implied warranty of
013: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: Lesser General Public License for more details.
015:
016: You should have received a copy of the GNU Lesser General Public
017: License along with this library; if not, write to the Free Software
018: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019:
020: For full license text, see doc/license/lgpl.txt in this distribution
021: */
022:
023: package drjava.smyle.tests;
024:
025: import drjava.util.*;
026: import drjava.smyle.*;
027: import drjava.smyle.testtypes.*;
028:
029: public class SmyleBench extends Benchmark {
030: static final int n = 250000, commitFrequency = 1000000;
031: Store store;
032: Snapshot snapshot;
033: Table<Person> table;
034:
035: public SmyleBench() {
036: setDescription("Adding, indexing and removing " + n
037: + " Person records");
038: }
039:
040: void commit() {
041: snapshot.commitAndContinue();
042: /*snapshot.commit();
043: snapshot = store.mutableSnapshot();
044: table = snapshot.getTable("people", Person.getTypeInfo());*/
045: }
046:
047: void add() {
048: for (int i = 0; i < n; i++) {
049: table.add(new Person(String.valueOf(i), i));
050: //table.remove(0);
051: if (i % commitFrequency == commitFrequency - 1)
052: commit();
053: }
054: done("add " + n + " records");
055: }
056:
057: void removeFromTop() {
058: for (int i = 0; i < n; i++)
059: table.remove(0);
060: done("remove all records from top");
061: }
062:
063: void removeFromBottom() {
064: for (int i = n - 1; i >= 0; i--)
065: table.remove(i);
066: done("remove all records from bottom");
067: }
068:
069: void removeFromTopFilter() {
070: for (int i = 0; i < n; i++) {
071: table.removeAll(new Person_filter().ageEquals(i));
072: if (table.size() != n - i - 1)
073: throw new RuntimeException(
074: "Wrong table size (expected " + (n - i - 1)
075: + ", was " + table.size() + ")");
076: }
077: done("remove all records from top (through filter)");
078: }
079:
080: void removeFromTopByStringField() {
081: for (int i = 0; i < n; i++) {
082: table.removeAll(new Person_filter().nameEquals(String
083: .valueOf(i)));
084: if (table.size() != n - i - 1)
085: throw new RuntimeException(
086: "Wrong table size (expected " + (n - i - 1)
087: + ", was " + table.size() + ")");
088: }
089: done("remove all records from top (filter on string field)");
090: }
091:
092: void removeFromTopByTwoFields() {
093: for (int i = 0; i < n; i++) {
094: table.removeAll(i % 2 == 0 ? new Person_filter()
095: .ageEquals(i) : new Person_filter()
096: .nameEquals(String.valueOf(i)));
097: if (table.size() != n - i - 1)
098: throw new RuntimeException(i
099: + ": wrong table size (expected " + (n - i - 1)
100: + ", was " + table.size() + ")");
101: }
102: done("remove all records from top (through alternating filters)");
103: }
104:
105: protected void action() {
106: store = Smyle.createEmptyStore("temp/bench");
107: store.setGCFrequency(1000000);
108: try {
109: ((drjava.smyle.core.DiskStore) store).enableIndexing();
110: snapshot = store.mutableSnapshot();
111: table = snapshot.getTable("people", Person.getTypeInfo());
112:
113: add();
114: //System.gc(); System.exit(0);
115: //removeFromTop();
116: //removeFromBottom();
117: snapshot.commitAndContinue();
118: done("commit");
119: removeFromTopFilter();
120: //removeFromTopByStringField();
121: //removeFromTopByTwoFields();
122:
123: //System.gc();
124: //System.exit(0); // highest mem usage should be about here
125:
126: snapshot.commit();
127: done("commit");
128: } finally {
129: store.close();
130: done("close store");
131: }
132: }
133:
134: public static void main(String[] args) {
135: for (int i = 0; i < 1; i++) {
136: SmyleBench bench = new SmyleBench();
137: bench.runAndPrint();
138: System.out.println("Records/s: "
139: + (long) (n / (bench.totalTime() * 0.001)));
140: }
141: System.gc(); // for memprofile; store is closed, but still referenced
142: }
143: }
|