179
|
1 package jp.ac.u_ryukyu.ie.cr.tatsuki.jungle.test;
|
|
2
|
180
|
3 import fj.Ord;
|
183
|
4 import fj.data.List;
|
|
5 import fj.data.Option;
|
180
|
6 import fj.data.TreeMap;
|
179
|
7 import org.xml.sax.SAXException;
|
|
8
|
|
9 import javax.xml.parsers.ParserConfigurationException;
|
|
10 import java.io.*;
|
|
11
|
|
12 /**
|
|
13 * Created by e115731 on 15/03/17.
|
|
14 */
|
|
15 public class TreeMapBenchMark {
|
|
16 public static void main(String[] args) throws InterruptedException, IOException, ParserConfigurationException, SAXException {
|
180
|
17
|
179
|
18
|
180
|
19 if (args.length == 0) {
|
183
|
20 System.out.println("args get or getLoop or list");
|
180
|
21 System.exit(0);
|
|
22 }
|
|
23
|
179
|
24 Runtime rt = Runtime.getRuntime();
|
|
25 int cpuNum = rt.availableProcessors();
|
|
26
|
183
|
27 File file = new File("./time/" + args[0] + "Time");
|
180
|
28
|
179
|
29 PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter(file)));
|
180
|
30
|
|
31 AbstractTreeMapThread readThread[] = null;
|
|
32
|
183
|
33 TreeMap<String, String> map = TreeMap.empty(Ord.stringOrd);
|
|
34 List<String> list = List.nil();
|
|
35 if (args[0].equals("list")) {
|
|
36 for (int count = 0 ;count < 100 ; count++) {
|
|
37 list = list.cons(String.valueOf(count));
|
|
38 }
|
|
39 }
|
|
40 for (int count = 0 ;count < 1000 ; count++) {
|
|
41 map = map.set(String.valueOf(count), String.valueOf(count));
|
|
42 }
|
|
43 for (int THREAD_COUNT = 1; THREAD_COUNT <= cpuNum; THREAD_COUNT++) {
|
|
44
|
180
|
45 readThread = new AbstractTreeMapThread[THREAD_COUNT];
|
|
46
|
183
|
47 if (args[0].equals("getLoop")) {
|
180
|
48 for (int count = 0; THREAD_COUNT > count; count++) {
|
183
|
49 readThread[count] = new FJTreeMapGetLoopThread(map);
|
180
|
50 }
|
183
|
51 } else if (args[0].equals("get")) {
|
180
|
52 for (int count = 0; THREAD_COUNT > count; count++) {
|
183
|
53 readThread[count] = new FJTreeMapGetIteratorThread(map);
|
180
|
54 }
|
183
|
55 } else if (args[0].equals("list")) {
|
|
56 for (int count = 0; THREAD_COUNT > count; count++) {
|
|
57 readThread[count] = new FJListAccessThread(Option.<List<String>>some(list));
|
|
58 }
|
|
59 } else{
|
180
|
60 System.out.println("not allow args");
|
|
61 System.exit(0);
|
|
62 }
|
179
|
63
|
|
64 for (int count = 0; THREAD_COUNT > count; count++) {
|
|
65 readThread[count].start();
|
|
66 }
|
|
67
|
|
68 System.out.println("StartThread");
|
|
69
|
|
70 Thread.sleep(1000);
|
|
71 long readCount = 0;
|
|
72
|
|
73 for (int count = 0; THREAD_COUNT > count; count++) {
|
|
74 readCount = readCount + readThread[count].getFindCount();
|
|
75 readThread[count].set(false);
|
|
76 }
|
|
77
|
|
78 pw.println(THREAD_COUNT + " " + readCount);
|
|
79 System.out.println(THREAD_COUNT + "readCount = " + readCount);
|
|
80 }
|
|
81
|
|
82 pw.close();
|
|
83 }
|
|
84
|
|
85 }
|