]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.db.tests/src/org/simantics/db/tests/performance/read/BtreeTest.java
Added missing org.simantics.db.{tests,testing} plug-ins.
[simantics/platform.git] / tests / org.simantics.db.tests / src / org / simantics / db / tests / performance / read / BtreeTest.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.db.tests.performance.read;
13
14 import java.util.UUID;
15
16 import org.simantics.databoard.Bindings;
17 import org.simantics.databoard.binding.mutable.Variant;
18 import org.simantics.datatypes.utils.BTreeUtils;
19 import org.simantics.db.Resource;
20 import org.simantics.db.Session;
21 import org.simantics.db.WriteGraph;
22 import org.simantics.db.common.request.WriteResultRequest;
23 import org.simantics.db.exception.DatabaseException;
24 import org.simantics.db.service.VirtualGraphSupport;
25 import org.simantics.db.testing.base.ExistingDatabaseTest;
26
27
28 public class BtreeTest extends ExistingDatabaseTest {
29
30         public static final int NODE_SIZE = 10;
31         public static final int TEN = 10;
32         public static final int THOUSAND = 1000;
33         public static final int MILLION = 1000000;
34
35         public static final int KEY_SIZE = TEN * THOUSAND;
36
37         public void test() throws Exception {
38
39                 Session session = getSession();
40
41                 VirtualGraphSupport vgss = session.getService(VirtualGraphSupport.class);
42
43                 long start = System.nanoTime();
44
45                 session.sync(new WriteResultRequest<Resource>(vgss.getMemoryPersistent(UUID.randomUUID().toString())) {
46
47                         @Override
48                         public Resource perform(WriteGraph graph) throws DatabaseException {
49
50                                 BTreeUtils bu = BTreeUtils.create(graph, null, NODE_SIZE, false);
51                                 for(int i=0;i<KEY_SIZE;i++) {
52                                         Resource value = graph.newResource();
53                                         graph.claim(value, L0.InstanceOf, null, L0.String);
54                                         graph.claimValue(value, "Value" + i, Bindings.STRING);
55                                         bu.insert(graph, Variant.ofInstance(i), value);
56                                 }
57                                 return bu.getTree();
58
59                         }
60
61                 });
62
63                 long duration = System.nanoTime()-start;
64                 System.err.println("WRITE at " + 1e-9*duration + "s.");
65 //              start = System.nanoTime();
66 //
67 //              session.sync(new UniqueRead<Resource>() {
68 //
69 //                      @Override
70 //                      public Resource perform(ReadGraph graph) throws DatabaseException {
71 //                              return BtreeUtils.search(graph, tree, 3);
72 //                      }
73 //
74 //              });
75 //
76 //              duration = System.nanoTime()-start;
77 //              System.err.println("SEEK SINGLE at " + 1e-9*duration + "s.");
78 //              start = System.nanoTime();
79 //
80 //              session.sync(new ReadRequest() {
81 //
82 //                      @Override
83 //                      public void run(ReadGraph graph) throws DatabaseException {
84 //                              for(int i=0;i<KEY_SIZE;i++)
85 //                                      BtreeUtils.search(graph, tree, i);
86 //                      }
87 //
88 //              });
89 //
90 //              duration = System.nanoTime()-start;
91 //              System.err.println("SEEK ALL at " + 1e-9*duration + "s.");
92
93         }
94
95 }