--- /dev/null
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.db.tests.performance.read;
+
+import java.util.UUID;
+
+import org.simantics.databoard.Bindings;
+import org.simantics.databoard.binding.mutable.Variant;
+import org.simantics.datatypes.utils.BTreeUtils;
+import org.simantics.db.Resource;
+import org.simantics.db.Session;
+import org.simantics.db.WriteGraph;
+import org.simantics.db.common.request.WriteResultRequest;
+import org.simantics.db.exception.DatabaseException;
+import org.simantics.db.service.VirtualGraphSupport;
+import org.simantics.db.testing.base.ExistingDatabaseTest;
+
+
+public class BtreeTest extends ExistingDatabaseTest {
+
+ public static final int NODE_SIZE = 10;
+ public static final int TEN = 10;
+ public static final int THOUSAND = 1000;
+ public static final int MILLION = 1000000;
+
+ public static final int KEY_SIZE = TEN * THOUSAND;
+
+ public void test() throws Exception {
+
+ Session session = getSession();
+
+ VirtualGraphSupport vgss = session.getService(VirtualGraphSupport.class);
+
+ long start = System.nanoTime();
+
+ session.sync(new WriteResultRequest<Resource>(vgss.getMemoryPersistent(UUID.randomUUID().toString())) {
+
+ @Override
+ public Resource perform(WriteGraph graph) throws DatabaseException {
+
+ BTreeUtils bu = BTreeUtils.create(graph, null, NODE_SIZE, false);
+ for(int i=0;i<KEY_SIZE;i++) {
+ Resource value = graph.newResource();
+ graph.claim(value, L0.InstanceOf, null, L0.String);
+ graph.claimValue(value, "Value" + i, Bindings.STRING);
+ bu.insert(graph, Variant.ofInstance(i), value);
+ }
+ return bu.getTree();
+
+ }
+
+ });
+
+ long duration = System.nanoTime()-start;
+ System.err.println("WRITE at " + 1e-9*duration + "s.");
+// start = System.nanoTime();
+//
+// session.sync(new UniqueRead<Resource>() {
+//
+// @Override
+// public Resource perform(ReadGraph graph) throws DatabaseException {
+// return BtreeUtils.search(graph, tree, 3);
+// }
+//
+// });
+//
+// duration = System.nanoTime()-start;
+// System.err.println("SEEK SINGLE at " + 1e-9*duration + "s.");
+// start = System.nanoTime();
+//
+// session.sync(new ReadRequest() {
+//
+// @Override
+// public void run(ReadGraph graph) throws DatabaseException {
+// for(int i=0;i<KEY_SIZE;i++)
+// BtreeUtils.search(graph, tree, i);
+// }
+//
+// });
+//
+// duration = System.nanoTime()-start;
+// System.err.println("SEEK ALL at " + 1e-9*duration + "s.");
+
+ }
+
+}