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.*;
26:
27: public class MeasureInsertPerformanceScalability {
28:
29: public static class Item {
30:
31: public int value;
32:
33: public Item() {
34:
35: }
36:
37: public Item(int value_) {
38: value = value_;
39: }
40:
41: }
42:
43: private static final String FILE = "mips.yap";
44:
45: private static final int TOTAL_COUNT = 500000;
46:
47: private static final int BULK_COUNT = 5000;
48:
49: public static void main(String[] args) {
50: new MeasureInsertPerformanceScalability().run();
51: }
52:
53: private void run() {
54: prepare();
55: ObjectContainer objectContainer = Db4o.openFile(FILE);
56:
57: boolean bulk = false;
58: int count = 0;
59: while (count < TOTAL_COUNT) {
60: if (bulk) {
61: count += storeBulk(objectContainer);
62: } else {
63: count += storeSingle(objectContainer);
64: }
65: System.out.println("Objects: " + count);
66: bulk = !bulk;
67: }
68: objectContainer.close();
69: }
70:
71: private int storeSingle(ObjectContainer objectContainer) {
72: long start = System.currentTimeMillis();
73: objectContainer.set(new Item((int) start));
74: objectContainer.commit();
75: long stop = System.currentTimeMillis();
76: long duration = stop - start;
77: System.out.println("Single " + duration + "ms");
78: return 1;
79: }
80:
81: private int storeBulk(ObjectContainer objectContainer) {
82: long start = System.currentTimeMillis();
83: for (int i = 0; i < BULK_COUNT; i++) {
84: objectContainer.set(new Item((int) start));
85: }
86: objectContainer.commit();
87: long stop = System.currentTimeMillis();
88: long duration = stop - start;
89: System.out.println("Bulk " + duration + "ms");
90: return BULK_COUNT;
91: }
92:
93: private void prepare() {
94: Db4o.configure().objectClass(Item.class).objectField("value")
95: .indexed(true);
96: new File(FILE).delete();
97: }
98:
99: }
|