Mercurial > hg > Members > tatsuki > bench > jungle-core
comparison src/main/java/jp/ac/u_ryukyu/ie/cr/tatsuki/jungle/test/JungleBenchMark.java @ 183:066d9c5758dc
change TreeContext
author | tatsuki |
---|---|
date | Mon, 23 Mar 2015 15:44:28 +0900 |
parents | 67d4c68578cf |
children | 868a746996ad |
comparison
equal
deleted
inserted
replaced
182:67d4c68578cf | 183:066d9c5758dc |
---|---|
22 */ | 22 */ |
23 public class JungleBenchMark { | 23 public class JungleBenchMark { |
24 public static void main(String[] args) throws InterruptedException, IOException, ParserConfigurationException, SAXException { | 24 public static void main(String[] args) throws InterruptedException, IOException, ParserConfigurationException, SAXException { |
25 | 25 |
26 | 26 |
27 if (args.length == 0) { | 27 if (args.length < 1) { |
28 System.out.println("args read or find"); | 28 System.out.println("args[0] = read or find, args[1] = separate or nonSeparate"); |
29 System.exit(0); | 29 System.exit(0); |
30 } | |
31 | |
32 Jungle jungle = new DefaultJungle(null, "hoge", new DefaultTreeEditor(new DefaultTraverser())); | |
33 JungleTree tree = jungle.createNewTree("Person"); | |
34 JungleTreeEditor editor = tree.getTreeEditor(); | |
35 JungleTreeEditor newEditor = createTree(0,new DefaultNodePath(),editor); | |
36 if (newEditor.success().isA()) { | |
37 System.out.println("success faild"); | |
38 System.exit(1); | |
39 } | 30 } |
40 | 31 |
41 Runtime rt = Runtime.getRuntime(); | 32 Runtime rt = Runtime.getRuntime(); |
42 int cpuNum = rt.availableProcessors(); | 33 int cpuNum = rt.availableProcessors(); |
43 | 34 |
35 Jungle jungle = new DefaultJungle(null, "hoge", new DefaultTreeEditor(new DefaultTraverser())); | |
36 JungleTree trees[] = new JungleTree[cpuNum]; | |
44 | 37 |
45 File file = new File("./time/JungleTree" + args[0] + "Time"); | 38 if (args[1].equals("separate")){ |
39 for (int count = 0; count < cpuNum; count++) { | |
40 JungleTree tree = jungle.createNewTree("tree" + count); | |
41 JungleTreeEditor editor = tree.getTreeEditor(); | |
42 editor = editor.putAttribute(new DefaultNodePath(), "key", ByteBuffer.wrap(String.valueOf(0).getBytes())).b(); | |
43 JungleTreeEditor newEditor = createTree(0, new DefaultNodePath(), editor); | |
44 if (newEditor.success().isA()) { | |
45 System.out.println("success faild"); | |
46 System.exit(1); | |
47 } | |
48 trees[count] = tree; | |
49 } | |
50 } else { | |
51 JungleTree tree = jungle.createNewTree("tree" ); | |
52 JungleTreeEditor editor = tree.getTreeEditor(); | |
53 editor = editor.putAttribute(new DefaultNodePath(), "key", ByteBuffer.wrap(String.valueOf(0).getBytes())).b(); | |
54 JungleTreeEditor newEditor = createTree(0, new DefaultNodePath(), editor); | |
55 if (newEditor.success().isA()) { | |
56 System.out.println("success faild"); | |
57 System.exit(1); | |
58 } | |
59 trees[0] = tree; | |
60 } | |
61 | |
62 File file = new File("./time/" + args[1] + "JungleTree" + args[0] + "Time"); | |
46 | 63 |
47 PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(file))); | 64 PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(file))); |
48 | 65 |
49 JungleBenchMarkThread readThread[] = null; | 66 JungleBenchMarkThread readThread[] = null; |
50 | 67 |
51 for (int THREAD_COUNT = 1; THREAD_COUNT <= cpuNum; THREAD_COUNT++) { | 68 for (int THREAD_COUNT = 1; THREAD_COUNT <= cpuNum; THREAD_COUNT++) { |
52 readThread = new JungleBenchMarkThread[THREAD_COUNT]; | 69 readThread = new JungleBenchMarkThread[THREAD_COUNT]; |
53 | 70 JungleTree tree = null; |
54 if (args[0].equals("read")) { | 71 if (args[0].equals("read")) { |
55 for (int count = 0; THREAD_COUNT > count; count++) { | 72 for (int count = 0; THREAD_COUNT > count; count++) { |
73 if (args[1].equals("separate")) | |
74 tree = trees[count]; | |
75 else | |
76 tree = trees[0]; | |
56 readThread[count] = new readTreeAttributeThread(tree); | 77 readThread[count] = new readTreeAttributeThread(tree); |
57 } | 78 } |
58 } else if (args[0].equals("find")) { | 79 } else if (args[0].equals("find")) { |
59 for (int count = 0; THREAD_COUNT > count; count++) { | 80 for (int count = 0; THREAD_COUNT > count; count++) { |
81 if (args[1].equals("separate")) | |
82 tree = trees[count]; | |
83 else | |
84 tree = trees[0]; | |
60 readThread[count] = new findTreeAttributeThread(tree); | 85 readThread[count] = new findTreeAttributeThread(tree); |
61 } | 86 } |
62 } else { | 87 } else { |
63 System.out.println("not allow args"); | 88 System.out.println("not allow args"); |
64 System.exit(0); | 89 System.exit(0); |
74 long readCount = 0; | 99 long readCount = 0; |
75 | 100 |
76 for (int count = 0; THREAD_COUNT > count; count++) { | 101 for (int count = 0; THREAD_COUNT > count; count++) { |
77 readCount = readCount + readThread[count].getFindCount(); | 102 readCount = readCount + readThread[count].getFindCount(); |
78 readThread[count].set(false); | 103 readThread[count].set(false); |
104 readThread[count] = null; | |
79 } | 105 } |
80 | 106 |
81 pw.println(THREAD_COUNT + " " + readCount); | 107 pw.println(THREAD_COUNT + " " + readCount); |
82 System.out.println(THREAD_COUNT + "readCount = " + readCount); | 108 System.out.println(THREAD_COUNT + "readCount = " + readCount); |
109 System.gc(); | |
110 System.out.println("-------------GC--------------"); | |
111 Thread.sleep(1000); | |
83 } | 112 } |
84 | 113 |
85 pw.close(); | 114 pw.close(); |
86 } | 115 } |
87 | 116 |
88 static Integer nodeNum = 0; | 117 static Integer nodeNum = 1; |
118 | |
89 public static JungleTreeEditor createTree(int deep, NodePath path, JungleTreeEditor editor) { | 119 public static JungleTreeEditor createTree(int deep, NodePath path, JungleTreeEditor editor) { |
90 | 120 |
91 Random rnd = new Random(); | 121 Random rnd = new Random(); |
92 String value1 = String.valueOf(nodeNum); | 122 String value1 = String.valueOf(nodeNum); |
93 nodeNum ++; | 123 nodeNum++; |
94 String value2 = String.valueOf(nodeNum); | 124 String value2 = String.valueOf(nodeNum); |
95 nodeNum ++; | 125 nodeNum++; |
96 | 126 |
97 if (value1.equals("500")) | |
98 System.out.println("aaa"); | |
99 editor = editor.addNewChildAt(path, 0).b(); | 127 editor = editor.addNewChildAt(path, 0).b(); |
100 editor = editor.putAttribute(path.add(0), "key", ByteBuffer.wrap(value1.getBytes())).b(); | 128 editor = editor.putAttribute(path.add(0), "key", ByteBuffer.wrap(value1.getBytes())).b(); |
101 editor = editor.addNewChildAt(path, 1).b(); | 129 editor = editor.addNewChildAt(path, 1).b(); |
102 editor = editor.putAttribute(path.add(1), "key", ByteBuffer.wrap(value2.getBytes())).b(); | 130 editor = editor.putAttribute(path.add(1), "key", ByteBuffer.wrap(value2.getBytes())).b(); |
103 deep++; | 131 deep++; |