changeset 294:a23069461460

add RedBlackTree benchMark
author tatsuki
date Wed, 04 Jan 2017 05:17:13 +0900
parents 5f8250bc62c3
children 1a5f3d3f3437
files src/main/java/jp/ac/u_ryukyu/ie/cr/benchMark/DifferencialTree/DifferencialTreeBenchMark.java src/main/java/jp/ac/u_ryukyu/ie/cr/benchMark/JungleTreeCreater.java src/main/java/jp/ac/u_ryukyu/ie/cr/benchMark/index/CreateIndexBenchMark.java src/main/java/jp/ac/u_ryukyu/ie/cr/benchMark/tree/CreateListTreeBenchMark.java src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/manager/DefaultTransactionManager.java src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/manager/RedBlackTreeTransactionManager.java src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/core/treeeditor/RedBlack/RedBlackTreeEditorTest.java
diffstat 7 files changed, 109 insertions(+), 107 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/benchMark/DifferencialTree/DifferencialTreeBenchMark.java	Wed Jan 04 03:50:31 2017 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,87 +0,0 @@
-package jp.ac.u_ryukyu.ie.cr.benchMark.DifferencialTree;
-
-import jp.ac.u_ryukyu.ie.cr.jungle.DefaultJungle;
-import jp.ac.u_ryukyu.ie.cr.jungle.Jungle;
-import jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath.DefaultNodePath;
-import jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath.NodePath;
-import jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.jungleTreeEditor.JungleTreeEditor;
-import jp.ac.u_ryukyu.ie.cr.jungle.traverser.DefaultTraverser;
-import jp.ac.u_ryukyu.ie.cr.jungle.tree.JungleTree;
-import jp.ac.u_ryukyu.ie.cr.jungle.util.Either;
-import jp.ac.u_ryukyu.ie.cr.jungle.util.Error.Error;
-
-import java.nio.ByteBuffer;
-
-/**
- * Created by e115731 on 2016/12/20.
- */
-public class DifferencialTreeBenchMark {
-
-    public static void main(String args[]) {
-        Jungle jungle = new DefaultJungle(null, "hogehoge", new DefaultTraverser());
-        if (args.length == 0) {
-            System.out.println("args default or difference");
-            System.exit(0);
-        }
-
-        JungleTree tree = null;
-        if (args[0].equals("default"))
-            defaultJungleTreeBenchMark(jungle);
-        else
-            if (args[0].equals("difference"))
-                DifferenceJungleTreeBenchMark(jungle);
-            else {
-                System.out.println("args default or difference");
-                System.exit(0);
-            }
-    }
-
-    private static void DifferenceJungleTreeBenchMark(Jungle jungle) {
-        System.out.println("differencialTree");
-        for (int i = 1; i <= 100; i++) {
-            JungleTree tree = jungle.createNewDifferenceTree("Tree" + i);
-            Long t1 = System.currentTimeMillis();
-            NodePath path = new DefaultNodePath();
-            for (int j = 0; j < (20 * i ); j++) {
-                JungleTreeEditor editor = tree.getJungleTreeEditor();
-                Either<Error, JungleTreeEditor> either = editor.putAttribute(path,"key", ByteBuffer.wrap("value".getBytes()));
-                if (either.isA())
-                    return ;
-                editor = either.b();
-                either = editor.success();
-                if (either.isA())
-                    return ;
-            }
-            System.gc();
-            Long t2 = System.currentTimeMillis();
-            System.out.println((i * 20) + " " + (t2 - t1));
-        }
-    }
-
-    private static void defaultJungleTreeBenchMark(Jungle jungle) {
-        System.out.println("defaultTree");
-        for (int i = 1; i <= 10; i++) {
-            JungleTree tree = jungle.createNewTree("Tree" + i);
-            Long t1 = System.currentTimeMillis();
-            NodePath path = new DefaultNodePath();
-            for (int j = 0; j < (200 * i ); j++) {
-                JungleTreeEditor editor = tree.getJungleTreeEditor();
-                Either<Error, JungleTreeEditor> either = editor.addNewChildAt(path, 0);
-                if (either.isA())
-                    return ;
-                editor = either.b();
-                either = editor.putAttribute(path,"key", ByteBuffer.wrap("value".getBytes()));
-                if (either.isA())
-                    return ;
-                editor = either.b();
-                path = path.add(0);
-                either = editor.success();
-                if (either.isA())
-                    return ;
-            }
-
-            Long t2 = System.currentTimeMillis();
-            System.out.println((i * 200) + " " + (t2 - t1));
-        }
-    }
-}
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/benchMark/JungleTreeCreater.java	Wed Jan 04 03:50:31 2017 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/benchMark/JungleTreeCreater.java	Wed Jan 04 05:17:13 2017 +0900
@@ -30,16 +30,12 @@
 
     private JungleTreeEditor createTree(JungleTreeEditor editor, String key, String indexKey, int deps, NodePath path) {
         Either<Error, JungleTreeEditor> either;
-        for (int i = 0; i < 3; i++) {
+        for (int i = 0; i < 2; i++) {
             if (nodeCount == maxNodeCount || maxDeps == deps) {
                 return editor;
             }
-            either = editor.addNewChildAt(path, i);
-            if (either.isA())
-                Assert.fail();
-            editor = either.b();
-            String value = path.add(i).toString();
-            either = editor.putAttribute(path.add(i), key, ByteBuffer.wrap(value.getBytes()));
+            String value = String.valueOf(nodeCount);
+            either = editor.addNewChildAndPutAttribute(path, i,key,ByteBuffer.wrap(value.getBytes()));
             if (either.isA())
                 Assert.fail();
             editor = either.b();
@@ -49,7 +45,7 @@
             editor = either.b();
             nodeCount++;
         }
-        for (int i = 0; i < 3; i++) {
+        for (int i = 0; i < 2; i++) {
             editor = createTree(editor, key, indexKey, deps + 1, path.add(i));
         }
         return editor;
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/benchMark/index/CreateIndexBenchMark.java	Wed Jan 04 03:50:31 2017 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/benchMark/index/CreateIndexBenchMark.java	Wed Jan 04 05:17:13 2017 +0900
@@ -14,21 +14,38 @@
  */
 public class CreateIndexBenchMark {
     public static void main(String args[]) {
+        if (args.length == 0) {
+            System.out.println("args default or difference");
+            System.exit(0);
+        }
+        if (args[0].equals("default")) {
+            System.out.println("create default tree");
+        }
+        else {
+            System.out.println("create red black tree");
+        }
+
         String key = "key";
         String indexKey = "indexKey";
         Jungle jungle = new DefaultJungle(null, "hogehoge", new DefaultTraverser());
-        System.out.println("end create Tree");
 
-        for (int i = 1; i <= 500; i++) {
+        for (int i = 100; i <= 100000;) {
             Long t1 = System.currentTimeMillis();
-            JungleTree tree = jungle.createNewTree("Tree" + i);
-            JungleTreeEditor editor = tree.getJungleTreeEditor();
+            JungleTree tree;
+            if (args[0].equals("default")) {
+                tree = jungle.createNewTree("Tree" + i);
+            }
+            else {
+                tree = jungle.createNewRedBlackTree("Tree" + i, key);
+            }
+                JungleTreeEditor editor = tree.getJungleTreeEditor();
             NodePath path = new DefaultNodePath();
-            int maxNodeCount = 1 * i;
+            int maxNodeCount = i;
             JungleTreeCreater creater = new JungleTreeCreater(maxNodeCount);
             editor = creater.createTree(editor, key, indexKey, path);
             Long t2 = System.currentTimeMillis();
             System.out.println((i) + " " + (t2 - t1));
+            i = i + 100;
             System.gc(); //GCしないとクソみたいに重くなる
         }
     }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/benchMark/tree/CreateListTreeBenchMark.java	Wed Jan 04 05:17:13 2017 +0900
@@ -0,0 +1,79 @@
+package jp.ac.u_ryukyu.ie.cr.benchMark.tree;
+
+import jp.ac.u_ryukyu.ie.cr.jungle.DefaultJungle;
+import jp.ac.u_ryukyu.ie.cr.jungle.Jungle;
+import jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath.DefaultNodePath;
+import jp.ac.u_ryukyu.ie.cr.jungle.store.nodepath.NodePath;
+import jp.ac.u_ryukyu.ie.cr.jungle.transaction.editor.jungleTreeEditor.JungleTreeEditor;
+import jp.ac.u_ryukyu.ie.cr.jungle.traverser.DefaultTraverser;
+import jp.ac.u_ryukyu.ie.cr.jungle.tree.JungleTree;
+import jp.ac.u_ryukyu.ie.cr.jungle.util.Either;
+import jp.ac.u_ryukyu.ie.cr.jungle.util.Error.Error;
+
+import java.nio.ByteBuffer;
+
+public class CreateListTreeBenchMark {
+
+    public static void main(String args[]) {
+        Jungle jungle = new DefaultJungle(null, "hogehoge", new DefaultTraverser());
+        if (args.length == 0) {
+            System.out.println("args default or difference");
+            System.exit(0);
+        }
+
+        if (args[0].equals("default"))
+            defaultJungleTreeBenchMark(jungle);
+        else
+            if (args[0].equals("difference"))
+                DifferenceJungleTreeBenchMark(jungle);
+            else {
+                System.out.println("args default or difference");
+                System.exit(0);
+            }
+    }
+
+    private static void DifferenceJungleTreeBenchMark(Jungle jungle) {
+        System.out.println("differencialTree");
+        for (int i = 1; i <= 100; i++) {
+            JungleTree tree = jungle.createNewDifferenceTree("Tree" + i);
+            Long t1 = System.currentTimeMillis();
+            NodePath path = new DefaultNodePath();
+            for (int j = 0; j < (20 * i); j++) {
+                JungleTreeEditor editor = tree.getJungleTreeEditor();
+                Either<Error, JungleTreeEditor> either = editor.putAttribute(path, "key", ByteBuffer.wrap("value".getBytes()));
+                if (either.isA())
+                    return;
+                editor = either.b();
+                either = editor.success();
+                if (either.isA())
+                    return;
+            }
+            System.gc();
+            Long t2 = System.currentTimeMillis();
+            System.out.println((i * 20) + " " + (t2 - t1));
+        }
+    }
+
+    private static void defaultJungleTreeBenchMark(Jungle jungle) {
+        System.out.println("defaultTree");
+        for (int i = 1; i <= 10; i++) {
+            JungleTree tree = jungle.createNewTree("Tree" + i);
+            Long t1 = System.currentTimeMillis();
+            NodePath path = new DefaultNodePath();
+            for (int j = 0; j < (200 * i); j++) {
+                JungleTreeEditor editor = tree.getJungleTreeEditor();
+                Either<Error, JungleTreeEditor> either = editor.addNewChildAndPutAttribute(path, 0,"key", ByteBuffer.wrap("value".getBytes()));
+                if (either.isA())
+                    return;
+                editor = either.b();
+                path = path.add(0);
+                either = editor.success();
+                if (either.isA())
+                    return;
+            }
+
+            Long t2 = System.currentTimeMillis();
+            System.out.println((i * 200) + " " + (t2 - t1));
+        }
+    }
+}
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/manager/DefaultTransactionManager.java	Wed Jan 04 03:50:31 2017 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/manager/DefaultTransactionManager.java	Wed Jan 04 05:17:13 2017 +0900
@@ -66,8 +66,8 @@
         Index index = tip.getIndex();
         ParentIndex parentIndex = tip.getParentIndex();
         InterfaceTraverser traverser = new InterfaceTraverser(newRoot, index, parentIndex, true);
-        traverser.updateIndex(editNodeList);
-        //traverser.createIndex();
+        //traverser.updateIndex(editNodeList);
+        traverser.createIndex();
         TreeContext newTreeContext = new DefaultTreeContext(newRoot, tip, list, uuid, _treeName, nextRevision, traverser);
 
         if (repository.compareAndSet(newTreeContext.prev(), newTreeContext)) {
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/manager/RedBlackTreeTransactionManager.java	Wed Jan 04 03:50:31 2017 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/manager/RedBlackTreeTransactionManager.java	Wed Jan 04 05:17:13 2017 +0900
@@ -17,9 +17,6 @@
 import java.util.Iterator;
 import java.util.concurrent.atomic.AtomicReference;
 
-/**
- * Created by e115731 on 2017/01/04.
- */
 public class RedBlackTreeTransactionManager implements TransactionManager {
     private final AtomicReference<TreeContext> repository;
     private final TreeContext tip;
@@ -67,7 +64,7 @@
         TreeContext newTreeContext = new DefaultTreeContext(newRoot, tip, list, uuid, _treeName, nextRevision, traverser);
 
         if (repository.compareAndSet(newTreeContext.prev(), newTreeContext)) {
-            TransactionManager txManager = new DefaultTransactionManager(writer, newTreeContext, repository, uuid);
+            TransactionManager txManager = new RedBlackTreeTransactionManager(writer, newTreeContext, repository, uuid);
             return DefaultEither.newB(txManager);
         }
 
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/core/treeeditor/RedBlack/RedBlackTreeEditorTest.java	Wed Jan 04 03:50:31 2017 +0900
+++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/core/treeeditor/RedBlack/RedBlackTreeEditorTest.java	Wed Jan 04 05:17:13 2017 +0900
@@ -27,7 +27,7 @@
         JungleTree tree = jungle.createNewRedBlackTree("TreeName", "balanceKey");
         NodePath path = new DefaultNodePath();
 
-        for (int count = 1; count <= 10000; count++) {
+        for (int count = 1; count <= 1000; count++) {
             JungleTreeEditor editor = tree.getJungleTreeEditor();
             ByteBuffer value = ByteBuffer.wrap(("value" + count).getBytes());
             Either<Error, JungleTreeEditor> either = editor.addNewChildAndPutAttribute(path, 0, key, value);