1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.db.tests.performance.read;
14 import java.util.UUID;
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;
28 public class BtreeTest extends ExistingDatabaseTest {
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;
35 public static final int KEY_SIZE = TEN * THOUSAND;
37 public void test() throws Exception {
39 Session session = getSession();
41 VirtualGraphSupport vgss = session.getService(VirtualGraphSupport.class);
43 long start = System.nanoTime();
45 session.sync(new WriteResultRequest<Resource>(vgss.getMemoryPersistent(UUID.randomUUID().toString())) {
48 public Resource perform(WriteGraph graph) throws DatabaseException {
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);
63 long duration = System.nanoTime()-start;
64 System.err.println("WRITE at " + 1e-9*duration + "s.");
65 // start = System.nanoTime();
67 // session.sync(new UniqueRead<Resource>() {
70 // public Resource perform(ReadGraph graph) throws DatabaseException {
71 // return BtreeUtils.search(graph, tree, 3);
76 // duration = System.nanoTime()-start;
77 // System.err.println("SEEK SINGLE at " + 1e-9*duration + "s.");
78 // start = System.nanoTime();
80 // session.sync(new ReadRequest() {
83 // public void run(ReadGraph graph) throws DatabaseException {
84 // for(int i=0;i<KEY_SIZE;i++)
85 // BtreeUtils.search(graph, tree, i);
90 // duration = System.nanoTime()-start;
91 // System.err.println("SEEK ALL at " + 1e-9*duration + "s.");