001: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
002:
003: This file is part of the db4o open source object database.
004:
005: db4o is free software; you can redistribute it and/or modify it under
006: the terms of version 2 of the GNU General Public License as published
007: by the Free Software Foundation and as clarified by db4objects' GPL
008: interpretation policy, available at
009: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
010: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
011: Suite 350, San Mateo, CA 94403, USA.
012:
013: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
014: WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: for more details.
017:
018: You should have received a copy of the GNU General Public License along
019: with this program; if not, write to the Free Software Foundation, Inc.,
020: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
021: package com.db4o.util.io.spikes;
022:
023: import java.io.File;
024:
025: import com.db4o.Db4o;
026: import com.db4o.ObjectContainer;
027: import com.db4o.ObjectSet;
028: import com.db4o.io.IoAdapter;
029: import com.db4o.util.io.NIOFileAdapter;
030: import com.db4o.util.io.win32.Win32IoAdapter;
031:
032: /**
033: * @exclude
034: */
035: public class SimpleIoBenchmark {
036:
037: private static final String DBFILENAME = "SimpleIoBenchmark.yap";
038: private static final int ITERATIONS = 10000;
039:
040: public static void main(String[] args) {
041:
042: for (int i = 0; i < 3; ++i) {
043: System.out.println("*******************");
044: test("Default IO adapter", null);
045: test("NIOFileadapter", new NIOFileAdapter(1024 * 32, 16));
046: test("Win32IoAdapter", new Win32IoAdapter());
047: }
048:
049: }
050:
051: private static void test(String name, IoAdapter adapter) {
052: if (null != adapter) {
053: Db4o.configure().io(adapter);
054: }
055:
056: long start = System.currentTimeMillis();
057: store();
058: query();
059: long elapsed = System.currentTimeMillis() - start;
060:
061: // System.gc is necessary to circumvent
062: // http://bugs.sun.com/bugdatabase/view_bug.do;:YfiG?bug_id=4724038
063: System.gc();
064:
065: System.out.println(name);
066: System.out.println("\t" + elapsed + "ms");
067: File file = new File(DBFILENAME);
068: System.out.println("\tFile size is " + file.length()
069: + " bytes.");
070: System.out
071: .println("\t" + file.length() / elapsed + " bytes/ms");
072: if (!file.delete()) {
073: System.err.println("Unable to delete '" + DBFILENAME + "'");
074: }
075: }
076:
077: private static void query() {
078: ObjectContainer db = Db4o.openFile(DBFILENAME);
079: try {
080: ObjectSet set = db.get(TestDummy.class);
081: if (ITERATIONS != set.size()) {
082: System.err.println("Expected: " + ITERATIONS
083: + ", actual: " + set.size());
084: }
085: } finally {
086: db.close();
087: }
088: }
089:
090: private static void store() {
091:
092: ObjectContainer db = Db4o.openFile(DBFILENAME);
093: try {
094: for (int i = 0; i < ITERATIONS; ++i) {
095: db.set(new TestDummy("Dummy " + i));
096: if (0 == i % 10) {
097: db.commit();
098: }
099: }
100: } finally {
101: db.close();
102: }
103: }
104: }
|