-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMinnerTimer.java
157 lines (118 loc) · 3.75 KB
/
MinnerTimer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.sql.Timestamp;
public class MinnerTimer {
public final static int MAX_DIFF = 7;
public final static int MAX_SUBDIFF = 7;
private final static String DIFF_MILLS_FILE = "diffcult_time.csv";
private final static String FILE_ENCODE = "UTF-8";
public static int[][] readDiffcultsMills() {
File file = new File(DIFF_MILLS_FILE);
if(false == file.exists()) {
return null;
}
int[][] times = null;
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(new FileInputStream(DIFF_MILLS_FILE), FILE_ENCODE));
times = new int[MAX_DIFF][MAX_SUBDIFF];
for (int i=0; i<MAX_DIFF; i++ ) {
for(int j=0; j<MAX_SUBDIFF; j++ ) {
times[i][j] = i * 60 * 1000 + j * 1000;
}
}
String line = null;
String[] strMills = null;
for (int i=0; i<MAX_DIFF; i++ ) {
if( (line = reader.readLine()) != null ) {
line = line.trim();
}
if (line == null || line.length() < 1) {
continue;
}
strMills = line.split(",");
if(strMills == null || strMills.length < 1) {
break;
}
for(int j=0; j<MAX_SUBDIFF && j< strMills.length; j++ ) {
times[i][j] = Integer.parseInt(strMills[j]);
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if(reader != null) {
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
System.out.println("read diffcults mills: ");
int last = MAX_SUBDIFF-1;
for (int i=0; i<MAX_DIFF; i++ ) {
for(int j=0; j<last; j++ ) {
System.out.print(times[i][j] + ",");
}
System.out.println(times[i][last]);
}
return times;
}
public static int[][] runMillsOfDiffcults() {
Timestamp genesisTime = new Timestamp(System.currentTimeMillis());
Block parent = new Block("genesis", genesisTime);
Block miner = new Block("uuid", new Timestamp(System.currentTimeMillis()), parent.getBlockID(), parent, null);
int[][] times = new int[MAX_DIFF][MAX_SUBDIFF];
PrintWriter timeWriter = null;
try {
timeWriter = new PrintWriter(DIFF_MILLS_FILE, FILE_ENCODE);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
int diffcult = 1;
int subDiffcult = 0;
long startTime = System.currentTimeMillis();
for(int i=0; i<MAX_DIFF ; i++) {
subDiffcult = 0;
for(int j=0; j<MAX_SUBDIFF ; j++) {
startTime = System.currentTimeMillis();
ProofWork powProof = new ProofWork();
powProof.setMainDiff(diffcult);
powProof.setSubDiff(subDiffcult);
miner.setProof(powProof);
miner.mineBlock();
times[i][j] = (int)(System.currentTimeMillis() - startTime);
System.out.println("Block Timed! " + miner.getBlockID() + ", diffcult " + diffcult + "." + subDiffcult + ", use time: " + times[i][j] + " ms");
timeWriter.print(times[i][j]);
if(j < MAX_SUBDIFF-1) {
timeWriter.print(",");
}
parent = miner;
miner = new Block("uuid" + parent.getBlockID(), new Timestamp(System.currentTimeMillis()), parent.getBlockID(), parent, null);
subDiffcult++;
}
timeWriter.println();
timeWriter.flush();
diffcult++;
}
timeWriter.close();
return times;
}
/*public static void main(String args[]) {
runMillsOfDiffcults();
readDiffcultsMills();
}*/
}