182
|
1 package jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.test;
|
|
2
|
|
3 import fj.Ord;
|
|
4 import fj.data.TreeMap;
|
|
5 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.DefaultJungle;
|
|
6 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.Jungle;
|
|
7 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTree;
|
|
8 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.JungleTreeEditor;
|
|
9 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.NodePath;
|
|
10 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultNodePath;
|
|
11 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.store.impl.DefaultTreeEditor;
|
|
12 import jp.ac.u_ryukyu.ie.cr.shoshi.jungle.traverser.DefaultTraverser;
|
|
13 import org.xml.sax.SAXException;
|
|
14
|
|
15 import javax.xml.parsers.ParserConfigurationException;
|
|
16 import java.io.*;
|
|
17 import java.nio.ByteBuffer;
|
|
18 import java.util.Random;
|
|
19
|
|
20 /**
|
|
21 * Created by e115731 on 15/03/20.
|
|
22 */
|
|
23 public class JungleBenchMark {
|
|
24 public static void main(String[] args) throws InterruptedException, IOException, ParserConfigurationException, SAXException {
|
|
25
|
|
26
|
|
27 if (args.length == 0) {
|
|
28 System.out.println("args read or find");
|
|
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 }
|
|
40
|
|
41 Runtime rt = Runtime.getRuntime();
|
|
42 int cpuNum = rt.availableProcessors();
|
|
43
|
|
44
|
|
45 File file = new File("./time/JungleTree" + args[0] + "Time");
|
|
46
|
|
47 PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(file)));
|
|
48
|
|
49 JungleBenchMarkThread readThread[] = null;
|
|
50
|
|
51 for (int THREAD_COUNT = 1; THREAD_COUNT <= cpuNum; THREAD_COUNT++) {
|
|
52 readThread = new JungleBenchMarkThread[THREAD_COUNT];
|
|
53
|
|
54 if (args[0].equals("read")) {
|
|
55 for (int count = 0; THREAD_COUNT > count; count++) {
|
|
56 readThread[count] = new readTreeAttributeThread(tree);
|
|
57 }
|
|
58 } else if (args[0].equals("find")) {
|
|
59 for (int count = 0; THREAD_COUNT > count; count++) {
|
|
60 readThread[count] = new findTreeAttributeThread(tree);
|
|
61 }
|
|
62 } else {
|
|
63 System.out.println("not allow args");
|
|
64 System.exit(0);
|
|
65 }
|
|
66
|
|
67 for (int count = 0; THREAD_COUNT > count; count++) {
|
|
68 readThread[count].start();
|
|
69 }
|
|
70
|
|
71 System.out.println("StartThread");
|
|
72
|
|
73 Thread.sleep(1000);
|
|
74 long readCount = 0;
|
|
75
|
|
76 for (int count = 0; THREAD_COUNT > count; count++) {
|
|
77 readCount = readCount + readThread[count].getFindCount();
|
|
78 readThread[count].set(false);
|
|
79 }
|
|
80
|
|
81 pw.println(THREAD_COUNT + " " + readCount);
|
|
82 System.out.println(THREAD_COUNT + "readCount = " + readCount);
|
|
83 }
|
|
84
|
|
85 pw.close();
|
|
86 }
|
|
87
|
|
88 static Integer nodeNum = 0;
|
|
89 public static JungleTreeEditor createTree(int deep, NodePath path, JungleTreeEditor editor) {
|
|
90
|
|
91 Random rnd = new Random();
|
|
92 String value1 = String.valueOf(nodeNum);
|
|
93 nodeNum ++;
|
|
94 String value2 = String.valueOf(nodeNum);
|
|
95 nodeNum ++;
|
|
96
|
|
97 if (value1.equals("500"))
|
|
98 System.out.println("aaa");
|
|
99 editor = editor.addNewChildAt(path, 0).b();
|
|
100 editor = editor.putAttribute(path.add(0), "key", ByteBuffer.wrap(value1.getBytes())).b();
|
|
101 editor = editor.addNewChildAt(path, 1).b();
|
|
102 editor = editor.putAttribute(path.add(1), "key", ByteBuffer.wrap(value2.getBytes())).b();
|
|
103 deep++;
|
|
104
|
|
105 if (deep < 10) {
|
|
106 editor = createTree(deep, path.add(0), editor);
|
|
107 editor = createTree(deep, path.add(1), editor);
|
|
108 }
|
|
109 return editor;
|
|
110 }
|
|
111 }
|