01: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
02:
03: This file is part of the db4o open source object database.
04:
05: db4o is free software; you can redistribute it and/or modify it under
06: the terms of version 2 of the GNU General Public License as published
07: by the Free Software Foundation and as clarified by db4objects' GPL
08: interpretation policy, available at
09: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11: Suite 350, San Mateo, CA 94403, USA.
12:
13: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14: WARRANTY; without even the implied warranty of MERCHANTABILITY or
15: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16: for more details.
17:
18: You should have received a copy of the GNU General Public License along
19: with this program; if not, write to the Free Software Foundation, Inc.,
20: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21: package com.db4o.test.performance;
22:
23: import java.io.*;
24:
25: import com.db4o.io.*;
26:
27: /**
28: *
29: * @exclude
30: */
31: public class RunIOBench {
32: public static void main(String[] args) throws IOException {
33:
34: RandomAccessFile recordedIn = new RandomAccessFile(
35: Util.BENCHFILE + ".1", "rw");
36: new File(Util.DBFILE).delete();
37: IoAdapter testadapt = new RandomAccessFileAdapter().open(
38: Util.DBFILE, false, 1024, false);
39:
40: // IoAdapter testadapt = new MemoryIoAdapter().open(Util.DBFILE, false,
41: // 1024);
42: // IoAdapter testadapt = new SymbianIoAdapter().open(Util.DBFILE,
43: // false, 1024);
44: long bench = benchmark(recordedIn, testadapt);
45: System.out
46: .println("tested IOAdapter: ["
47: + testadapt.getClass().getName() + "]\nspeed: "
48: + bench);
49: }
50:
51: public static long benchmark(RandomAccessFile recordedIn,
52: IoAdapter adapter) throws IOException {
53: byte[] defaultData = new byte[1000];
54: long start = System.currentTimeMillis();
55: int runs = 0;
56: try {
57: while (true) {
58: runs++;
59: char type = recordedIn.readChar();
60: if (type == 'q') {
61: break;
62: }
63: if (type == 'f') {
64: adapter.sync();
65: continue;
66: }
67: long pos = recordedIn.readLong();
68: int length = recordedIn.readInt();
69: adapter.seek(pos);
70: byte[] data = (length <= defaultData.length ? defaultData
71: : new byte[length]);
72: switch (type) {
73: case 'r':
74: adapter.read(data, length);
75: break;
76: case 'w':
77: adapter.write(data, length);
78: break;
79: default:
80: throw new IllegalArgumentException(
81: "Unknown access type: " + type);
82: }
83: }
84: } finally {
85: recordedIn.close();
86: adapter.close();
87: }
88: // System.err.println(runs);
89: return System.currentTimeMillis() - start;
90: }
91: }
|