Mercurial > hg > Members > shoshi > jungle > jungle-core
changeset 280:9f38fcb07d36
add DifferenceJungleTree BenchMark
author | tatsuki |
---|---|
date | Tue, 20 Dec 2016 18:17:18 +0900 |
parents | 86d44dd80b1c |
children | 8a746ab2dd02 |
files | src/main/java/jp/ac/u_ryukyu/ie/cr/benchMark/DifferencialTree/DifferencialTreeBenchMark.java src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/manager/DifferenceTransactionManager.java src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/core/treeeditor/Difference/MultiDifferencialJngleTreeEditorTest.java |
diffstat | 3 files changed, 91 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/benchMark/DifferencialTree/DifferencialTreeBenchMark.java Tue Dec 20 18:17:18 2016 +0900 @@ -0,0 +1,85 @@ +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) { + for (int i = 1; i <= 10; i++) { + JungleTree tree = jungle.createNewDifferenceTree("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.putAttribute(path,"key", ByteBuffer.wrap("value".getBytes())); + if (either.isA()) + return ; + editor = either.b(); + either = editor.success(); + if (either.isA()) + return ; + } + + Long t2 = System.currentTimeMillis(); + System.out.println("Node count = " + (i * 200) + " : time = " + (t2 - t1)); + } + } + + private static void defaultJungleTreeBenchMark(Jungle jungle) { + 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("Node count = " + (i * 200) + " : time = " + (t2 - t1)); + } + } +}
--- a/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/manager/DifferenceTransactionManager.java Mon Dec 19 22:10:14 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/jungle/transaction/manager/DifferenceTransactionManager.java Tue Dec 20 18:17:18 2016 +0900 @@ -72,10 +72,10 @@ if (tip.getAppendedNode() == null) return DefaultEither.newA(APPENDED_NODE_NULL); if (repository.compareAndSet(newTreeContext.prev(), newTreeContext)) { - traverser.createIndex(); - Either<Error, TreeNode> either = replaceUnDefineNode(subTreeRoot); + Either<Error, TreeNode> either = appendSubTree(subTreeRoot); if (either.isA()) return DefaultEither.newA(either.a()); + traverser.createIndex(); TransactionManager txManager = new DifferenceTransactionManager(writer, newTreeContext, repository, uuid); return DefaultEither.newB(txManager); } @@ -83,7 +83,7 @@ return DefaultEither.newA(CAS_MISS); } - private Either<Error, TreeNode> replaceUnDefineNode(TreeNode subTreeRoot) { + private Either<Error, TreeNode> appendSubTree(TreeNode subTreeRoot) { TreeNode appendedNode = tip.getAppendedNode(); TreeNodeChildren children = appendedNode.getChildren(); return children.addNewChildAt(0, subTreeRoot);
--- a/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/core/treeeditor/Difference/MultiDifferencialJngleTreeEditorTest.java Mon Dec 19 22:10:14 2016 +0900 +++ b/src/test/java/jp/ac/u_ryukyu/ie/cr/jungle/core/treeeditor/Difference/MultiDifferencialJngleTreeEditorTest.java Tue Dec 20 18:17:18 2016 +0900 @@ -14,6 +14,9 @@ /** * デバッガで確かめる + * 手順 + * Thread 1 を JungleTreeEditorの TransactionManager newTxManager = either.b();の部分で止める + * そしてThread 2で TreeContextのAppendedNode */ public class MultiDifferencialJngleTreeEditorTest { @Test