-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculateExecutedTime.java
More file actions
76 lines (62 loc) · 1.88 KB
/
CalculateExecutedTime.java
File metadata and controls
76 lines (62 loc) · 1.88 KB
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
package example.TimeExample;
/**
* Timer
*
* Reference:
* - https://www.gushiciku.cn/pl/gpRL/zh-tw
*/
public class CalculateExecutedTime {
// public interface Visitor {
// int doJob(int a, int b);
// }
public static void main(String[] args) {
// Timer.code(() -> {
// for1000();
// });
Timer.code(() -> {
for10000();
});
}
public static void for1000() {
for(int i=0; i<1000; i++) {
System.out.println(i);
}
}
public static void for10000() {
for(int i=0; i<10000; i++) {
System.out.println(i);
}
}
public static void executedTime() {
Visitor visitor = new Visitor() {
public int doJob(int a, int b) {
return a + b;
}
};
System.out.println(visitor.doJob(10, 20));
}
}
interface Visitor {
int doJob(int a, int b);
}
class Timer {
public static void code(Runnable block) {
long start = System.currentTimeMillis();
try {
block.run();
} finally {
long end = System.currentTimeMillis();
System.out.println("Time taken: " + (end - start) / 1.0e4);
}
}
// public static void contextLoad7() {
// // TODO: 結合Hutool library.
// TimeInterval timer = DateUtil.timer();
// long interval = timer.interval(); //花費毫秒數
// System.out.println("interval = " + interval);
// long intervalRestart = timer.intervalRestart(); //返回花費時間,並重置開始時間
// System.out.println("intervalRestart = " + intervalRestart);
// long intervalMinute = timer.intervalMinute(); //花費分鐘數
// System.out.println("intervalMinute = " + intervalMinute);
// }
}