Mercurial > hg > Members > tatsuki > jungle-bench
changeset 3:37aab24020a0
thread test
author | Kanagawa TATSUKI <tatsuki@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 06 Mar 2014 04:17:40 +0900 |
parents | f716298e440a |
children | 671a67571a48 |
files | .classpath .project .settings/org.eclipse.jdt.core.prefs src/main/java/example/SimpleJungle.java src/main/java/example/SimplejungleMalti.java src/main/java/example/WriteThread.java |
diffstat | 6 files changed, 195 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.classpath Thu Mar 06 04:17:40 2014 +0900 @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path="src/main/java" including="**/*.java"/> + <classpathentry kind="output" path="target/classes"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry kind="var" path="M2_REPO/jungle/jungle-core/0.0.3-SNAPSHOT/jungle-core-0.0.3-SNAPSHOT.jar"/> + <classpathentry kind="var" path="M2_REPO/com/google/guava/guava/12.0/guava-12.0.jar"/> + <classpathentry kind="var" path="M2_REPO/com/google/code/findbugs/jsr305/1.3.9/jsr305-1.3.9.jar"/> + <classpathentry kind="var" path="M2_REPO/commons-collections/commons-collections/3.2.1/commons-collections-3.2.1.jar"/> + <classpathentry kind="var" path="M2_REPO/org/functionaljava/functionaljava/3.1/functionaljava-3.1.jar"/> + <classpathentry kind="var" path="M2_REPO/org/apache/maven/surefire/surefire-junit4/2.13/surefire-junit4-2.13.jar"/> + <classpathentry kind="var" path="M2_REPO/org/apache/maven/surefire/surefire-api/2.13/surefire-api-2.13.jar"/> + <classpathentry kind="var" path="M2_REPO/junit/junit/4.7/junit-4.7.jar"/> +</classpath> \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.project Thu Mar 06 04:17:40 2014 +0900 @@ -0,0 +1,14 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>jungle-bench</name> + <comment>NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse.</comment> + <projects/> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.settings/org.eclipse.jdt.core.prefs Thu Mar 06 04:17:40 2014 +0900 @@ -0,0 +1,5 @@ +#Tue Mar 04 02:20:13 JST 2014 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.source=1.7 +org.eclipse.jdt.core.compiler.compliance=1.7
--- a/src/main/java/example/SimpleJungle.java Tue Mar 04 02:02:39 2014 +0900 +++ b/src/main/java/example/SimpleJungle.java Thu Mar 06 04:17:40 2014 +0900 @@ -24,37 +24,39 @@ 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(); - DefaultNodePath root = new DefaultNodePath(); + 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()){ + 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(); - either = editor1.addNewChildAt(root,0); - if(either.isA()){ + editor1 = tree.getTreeEditor();//Treeのeditorを作成 + either = editor1.addNewChildAt(root,0);//新しく入れるところへのパス + if(either.isA()){//ちゃんとパスを指定できたかチェック Assert.fail(); } - editor1 = either.b(); + editor1 = either.b();//成功した場合パスを入れる DefaultNodePath childPath = root.add(0); - either = editor1.putAttribute(childPath,key,value); - if(either.isA()){ + //そしてここで子ノードに値を入れる + for(int count = 0 ; count < 1000 ; count++){ + either = editor1.putAttribute(childPath,key,value); + if(either.isA()){ Assert.fail(); - } - editor1 = either.b(); - either = editor1.success(); - if(either.isA()){ - Assert.fail(); + } + editor1 = either.b(); + either = editor1.success(); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/example/SimplejungleMalti.java Thu Mar 06 04:17:40 2014 +0900 @@ -0,0 +1,91 @@ +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 roopCount = 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の取得 + 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();//成功した場合パスを入れる + NodePath childPath = root.add(0); + either = editor1.success(); + + //そしてここで子ノードに値を入れる + + long t1 = System.currentTimeMillis();//時間の測定開始 + + for(int count = 0 ; count < threadCount ; count++){ + wt[count] = new WriteThread(j,childPath ,(roopCount/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); + + 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())); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/example/WriteThread.java Thu Mar 06 04:17:40 2014 +0900 @@ -0,0 +1,53 @@ +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.store.impl.DefaultNodePath; +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()); + Either<Error,JungleTreeEditor> either; + JungleTreeEditor editor; + JungleTree tree; + Jungle j; + NodePath childPath; + int roopCount; + int num; + WriteThread(Jungle j,NodePath childPath , int roopCount , int num) { + this.num = num; + this.valueString = this.valueString + Integer.toString(num); + this.value = ByteBuffer.wrap(valueString.getBytes()); + this.roopCount = roopCount; + this.j = j; + this.childPath = childPath; + } + +public void run() { + tree = j.getTreeByName("tree");//名前を取得 + editor = tree.getTreeEditor();//Treeのeditorを作成 + long t1 = System.currentTimeMillis();//時間の測定開始 + + for(int count = 0 ; count < roopCount ; count++){ + do{ + 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) +"秒"); + } +} +