-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRunTime.java
More file actions
46 lines (38 loc) · 808 Bytes
/
Copy pathRunTime.java
File metadata and controls
46 lines (38 loc) · 808 Bytes
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
/*
获取一段程序的运行时间。
原理:获取程序开始和结束的时间并相减
*/
/*
获取时间:System.currentTimeMillis();
*/
abstract class GetTime
{
public final void getTime()
{
long start = System.currentTimeMillis();
runCode();
long end = System.currentTimeMillis();
System.out.println("毫秒:"+(end-start));
}
public abstract void runCode();
}
class SubTime extends GetTime
{
public void runCode()
{
for (int i = 0; i <= 100000; i++)
{
if (100000 == i)
System.out.println("over!");
}
}
}
class RunTime
{
public static void main(String[] args)
{
SubTime gt = new SubTime();
//GetTime gt = new GetTime();
gt.getTime();
}
}