Mercurial > hg > Members > tatsuki > jungle-bench
changeset 9:ae1faea6f7c9
add GetOldTreeTime
author | one |
---|---|
date | Fri, 14 Nov 2014 00:55:30 +0900 |
parents | 442463aa27e5 |
children | 2af5af044947 |
files | src/main/java/example/ReadThread.java src/main/java/example/SimpleJungle.java src/main/java/example/SimpleJungleRead.java src/main/java/example/SimplejungleMalti.java src/main/java/example/WriteThread.java src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/oldTree/GetOldTreeTime.java |
diffstat | 6 files changed, 41 insertions(+), 397 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/example/ReadThread.java Tue Apr 01 18:28:34 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,57 +0,0 @@ -package example; - -import java.nio.ByteBuffer; - -import fj.data.List; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.Jungle; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Node; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TraversableNodeWrapper; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.DefaultEvaluator; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.DefaultTraverser; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.Traversal; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; -import junit.framework.Assert; - -public class ReadThread extends Thread { - public static final String key = "name"; - int loopCount; - Jungle j; - List<DefaultNodePath> paths; - - ReadThread(Jungle j, int loopCount, List<DefaultNodePath> paths) { - this.loopCount = loopCount; - System.out.println(loopCount); - this.paths = paths; - this.j = j; - } - - public void run() { - JungleTree tree = j.getTreeByName("tree"); - DefaultTraverser traverser = new DefaultTraverser(); - TraversableNodeWrapper<Node> traversable = new TraversableNodeWrapper<Node>( - tree.getRootNode()); - for (int count = 0; count < loopCount; count++) { - for (DefaultNodePath path : paths) { - DefaultEvaluator evaluator = new DefaultEvaluator(path); - Either<Error, Traversal<TraversableNodeWrapper<Node>>> ret = traverser - .traverse(traversable, evaluator); - if (ret.isA()) { - Assert.fail(); - } - - Traversal<TraversableNodeWrapper<Node>> traversal = ret.b(); - TraversableNodeWrapper<Node> target = traversal.destination(); - ByteBuffer value = target.getWrapped().getAttributes().get(key); - String actual = new String(value.array()); - System.out.println(actual); - // List<DefaultNodePath> parts = path.inits(); - } - - } - - // ここまで処理 - } -}
--- a/src/main/java/example/SimpleJungle.java Tue Apr 01 18:28:34 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,73 +0,0 @@ -package example; - -import java.nio.ByteBuffer; - -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.DefaultJungle; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.Jungle; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Children; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Node; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultTreeEditor; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.DefaultTraverser; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; -import junit.framework.Assert; - - -public class SimpleJungle { - - public static final String key = "name"; - public static final String valueString = "kanagawa"; - public static final ByteBuffer value = ByteBuffer.wrap(valueString.getBytes()); - - public static void main(String[] args) { - Jungle j = new DefaultJungle(null,"hogehoge",new DefaultTreeEditor(new DefaultTraverser())); - j.createNewTree("tree");//木を作った - JungleTree tree = j.getTreeByName("tree");//名前を取得 - JungleTreeEditor editor1 = tree.getTreeEditor();//editorの取得 - DefaultNodePath root = new DefaultNodePath();//パスの取得 - - //eitherに値を入れる - Either<Error,JungleTreeEditor> either = editor1.putAttribute(root,key,value); - if(either.isA()){//失敗した場合Aが出てくる - Assert.fail(); - } - editor1 = either.b(); - editor1.success(); - //ここで初めてSUCCESS - - Node node = tree.getRootNode(); - ByteBuffer v = node.getAttributes().get(key); - System.out.println(new String(v.array())); - - editor1 = tree.getTreeEditor();//Treeのeditorを作成 - either = editor1.addNewChildAt(root,0);//新しく入れるところへのパス - if(either.isA()){//ちゃんとパスを指定できたかチェック - Assert.fail(); - } - editor1 = either.b();//成功した場合パスを入れる - DefaultNodePath childPath = root.add(0); - //そしてここで子ノードに値を入れる - for(int count = 0 ; count < 1000 ; count++){ - either = editor1.putAttribute(childPath,key,value); - if(either.isA()){ - Assert.fail(); - } - editor1 = either.b(); - either = editor1.success(); - } - - - node = tree.getRootNode(); - Children<Node> children = node.getChildren(); - Either<Error,Node> either2 = children.at(0); - if(either2.isA()){ - Assert.fail(); - } - Node childNode = either2.b(); - ByteBuffer v2 = childNode.getAttributes().get(key); - System.out.println(new String(v2.array())); - } -}
--- a/src/main/java/example/SimpleJungleRead.java Tue Apr 01 18:28:34 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,120 +0,0 @@ -package example; - -import java.nio.ByteBuffer; - -import fj.data.List; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.DefaultJungle; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.Jungle; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultTreeEditor; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.DefaultTraverser; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; -import junit.framework.Assert; - -public class SimpleJungleRead extends Thread { - public static final String key = "name"; - public static final String valueString = "kanagawsa"; - public static final ByteBuffer value = ByteBuffer.wrap(valueString - .getBytes()); - - public static void main(String[] args) { - System.out.println("タスク数" + args[0]); - System.out.println("CPU数" + args[1]); - int loopCount = Integer.parseInt(args[0]); - int threadCount = Integer.parseInt(args[1]); - - ReadThread[] wt = new ReadThread[threadCount]; - Jungle j = new DefaultJungle(null, "hogehoge", new DefaultTreeEditor( - new DefaultTraverser())); - j.createNewTree("tree");// 木を作った - JungleTree tree = j.getTreeByName("tree");// 名前を取得 - // JungleTreeEditor editor1 = tree.getTreeEditor();// editorの取得 - // NodePath root = new DefaultNodePath();// パスの取得 - - // ------子ノードの追加 - List<DefaultNodePath> paths = generatePathPattern( - new DefaultNodePath(), 0, 3); - CreateTree(tree); - // ここまでノードの追加 - - // ここで処理を行う - - for (int count = 0; count < threadCount; count++) { - wt[count] = new ReadThread(j, (loopCount / threadCount), paths); - } - long t1 = System.currentTimeMillis();// 時間の測定開始 - for (int count = 0; count < threadCount; count++) { - wt[count].start(); - } - - for (int count = 0; count < threadCount; count++) { - try { - wt[count].join(); - } catch (InterruptedException e) { - } - } - - long t2 = System.currentTimeMillis(); - System.out.println(t2 - t1 + "s"); - - } - - public static List<DefaultNodePath> generatePathPattern( - DefaultNodePath _cur, int _curHeight, int _maxHeight) { - List<DefaultNodePath> paths = List.nil(); - for (int p = 0; p <= _curHeight && p < 2; p++) { - DefaultNodePath path = _cur.add(p); - if (_curHeight != _maxHeight - 1) { - List<DefaultNodePath> newpaths = generatePathPattern(path, - _curHeight + 1, _maxHeight); - paths = paths.append(newpaths); - } - paths = paths.cons(path); - } - - return paths; - } - - public static void CreateTree(JungleTree tree) { - NodePath root = new DefaultNodePath(); - CreateChildren(tree, root, 0); - - for (int x = 0; x < 2; x++) { - // ノードの追加 - CreateChildren(tree, root.add(0), x); - for (int y = 0; y < 2; y++) { - CreateChildren(tree, root.add(0).add(x), y); - } - } - - } - - public static void CreateChildren(JungleTree tree, NodePath root, int num) { - JungleTreeEditor editor = tree.getTreeEditor();// Treeのeditorを作成 - Either<Error, JungleTreeEditor> either = editor.addNewChildAt(root, - num); // 新しく入れるところへのパス - if (either.isA()) {// ちゃんとパスを指定できたかチェック - Assert.fail(); - } - editor = either.b();// 成功した場合パスを入れる - // NodePath childPath = root.add(x); - either = editor.success(); - if (either.isA()) {// SUCCESSがちゃんと成功したかを調べる - Assert.fail(); - } - // ここまでノードの追加 - NodePath childPath = root.add(num); - editor = tree.getTreeEditor();// Treeのeditorを作成 - either = editor.putAttribute(childPath, key, - ByteBuffer.wrap("Blazblue".getBytes())); - if (either.isA()) { - Assert.fail(); - } - editor = either.b(); - either = editor.success(); - } -}
--- a/src/main/java/example/SimplejungleMalti.java Tue Apr 01 18:28:34 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,96 +0,0 @@ -package example; - -import java.nio.ByteBuffer; - -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.DefaultJungle; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.Jungle; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Children; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.core.Node; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultTreeEditor; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.DefaultTraverser; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; -import junit.framework.Assert; - -public class SimplejungleMalti extends Thread { - public static final String key = "name"; - public static final String valueString = "kanagawsa"; - public static final ByteBuffer value = ByteBuffer.wrap(valueString - .getBytes()); - - public static void main(String[] args) { - System.out.println(args[0]); - System.out.println(args[1]); - int loopCount = Integer.parseInt(args[0]); - int threadCount = Integer.parseInt(args[1]); - WriteThread[] wt = new WriteThread[threadCount]; - Jungle j = new DefaultJungle(null, "hogehoge", new DefaultTreeEditor( - new DefaultTraverser())); - j.createNewTree("tree");// 木を作った - JungleTree tree = j.getTreeByName("tree");// 名前を取得 - JungleTreeEditor editor1 = tree.getTreeEditor();// editorの取得 - NodePath root = new DefaultNodePath();// パスの取得 - - // eitherに値を入れる - Either<Error, JungleTreeEditor> either = editor1.putAttribute(root, - key, value); - if (either.isA()) {// 失敗した場合Aが出てくる - Assert.fail(); - } - editor1 = either.b(); - editor1.success(); - // ここで初めてSUCCESS - - Node node = tree.getRootNode(); - ByteBuffer v = node.getAttributes().get(key); - System.out.println(new String(v.array())); - - // ------以下子ノードの作成 - editor1 = tree.getTreeEditor();// Treeのeditorを作成 - either = editor1.addNewChildAt(root, 0);// 新しく入れるところへのパス - if (either.isA()) {// ちゃんとパスを指定できたかチェック - Assert.fail(); - } - editor1 = either.b();// 成功した場合パスを入れる - NodePath childPath = root.add(0); - either = editor1.success(); - if (either.isA()) {// ちゃんとパスを指定できたかチェック - Assert.fail(); - } - // そしてここで子ノードに値を入れる - - long t1 = System.currentTimeMillis();// 時間の測定開始 - for (int count = 0; count < threadCount; count++) { - wt[count] = new WriteThread(j, childPath, - (loopCount / threadCount), count); - } - for (int count = 0; count < threadCount; count++) { - wt[count].start(); - } - - for (int count = 0; count < threadCount; count++) { - try { - wt[count].join(); - } catch (InterruptedException e) { - } - } - - long t2 = System.currentTimeMillis(); - System.out.println(t2 - t1 + "s"); - - node = tree.getRootNode(); - Children<Node> children = node.getChildren(); - Either<Error, Node> either2 = children.at(0); - if (either2.isA()) { - Assert.fail(); - } - - Node childNode = either2.b(); - ByteBuffer v2 = childNode.getAttributes().get(key); - System.out.println(new String(v2.array())); - } -}
--- a/src/main/java/example/WriteThread.java Tue Apr 01 18:28:34 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -package example; - -import java.nio.ByteBuffer; - -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.Jungle; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; -import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; -import junit.framework.Assert; - -public class WriteThread extends Thread { - public static final String key = "name"; - public String valueString = "tatsuki"; - public ByteBuffer value = ByteBuffer.wrap(valueString.getBytes()); - Jungle j; - NodePath childPath; - int loopCount; - int num; - - WriteThread(Jungle j, NodePath childPath, int loopCount, int num) { - this.num = num; - this.valueString = this.valueString + Integer.toString(num); - this.value = ByteBuffer.wrap(valueString.getBytes()); - this.loopCount = loopCount; - this.j = j; - this.childPath = childPath; - } - - public void run() { - JungleTree tree = j.getTreeByName("tree");// 名前を取得 - Either<Error, JungleTreeEditor> either; - System.out.println("loopCount = " + loopCount); - long t1 = System.currentTimeMillis();// 時間の測定開始 - - for (int count = 0; count < loopCount; count++) { - do { - JungleTreeEditor editor = tree.getTreeEditor();// Treeのeditorを作成 - either = editor.putAttribute(childPath, key, value); - if (either.isA()) { - Assert.fail(); - } - editor = either.b(); - either = editor.success(); - } while (either.isA()); - } - long t2 = System.currentTimeMillis(); - System.out.println(num + "番目終わり" + (t2 - t1) + "秒"); - } -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/oldTree/GetOldTreeTime.java Fri Nov 14 00:55:30 2014 +0900 @@ -0,0 +1,41 @@ +package jp.ac.u_ryukyu.ie.cr.tatsuki.oldTree; + +import java.nio.ByteBuffer; + +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.DefaultJungle; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.Jungle; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultTreeEditor; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.TreeNode; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.DefaultTraverser; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Either; +import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.util.Error; +import junit.framework.Assert; + +public class GetOldTreeTime { + + public static void main(String args[]) { + Jungle jungle = new DefaultJungle(null, "hogehoge", new DefaultTreeEditor(new DefaultTraverser())); + jungle.createNewTree("tree"); + JungleTree tree = jungle.getTreeByName("tree"); + JungleTreeEditor editor = tree.getTreeEditor(); + DefaultNodePath path = new DefaultNodePath(); + + editor = editor.addNewChildAt(path, 0).b().success().b(); + + for (int num = 0; num < 1000000; num++) { + JungleTreeEditor putAttributeEditor = editor.putAttribute(path.add(0), "test", ByteBuffer.wrap("tatsuki".getBytes())).b(); + Either<Error, JungleTreeEditor> successEither = putAttributeEditor.success(); + Assert.assertFalse(successEither.isA()); + editor = successEither.b(); + } + System.out.println("TreeRevision = " + tree.revision()); + long t1 = System.currentTimeMillis(); + JungleTree oldTree = tree.getOldTree(1).b(); + long t2 = System.currentTimeMillis(); + System.out.println("time = " + (t2 - t1)); + System.out.println("oldTreeRevision = " + oldTree.revision()); + } +}