-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathCountTimer.java
More file actions
59 lines (54 loc) · 1.82 KB
/
CountTimer.java
File metadata and controls
59 lines (54 loc) · 1.82 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
package common.base.utils;
/**
* ******************(^_^)***********************<br>
* User: 11776610771@qq.com<br>
* Date: 2017/10/12<br>
* Time: 9:52<br>
* <P>DESC:
* 统计开始到结束的所用的时间
* 注意,这个只适合单线程
* </p>
* ******************(^_^)***********************
*/
public class CountTimer {
private static final String TAG = "CountTimer";
private static long startTime;
public static void start() {
startTime = System.currentTimeMillis();
}
public static void end() {
end(null);
}
public static void end(String logTag) {
end(logTag, null);
}
public static void end(String logTag, String logExtraInfo) {
end(logTag, logExtraInfo, 1);
}
/**
* 结束计时,并且输出打印信息
* @param logTag Log 的tag,如果为null 则用本类的TAG="CountTimer"
* @param logExtraInfo Log的内容 : 如果为null,则直接是"-->end() experience time: ",否则,为 "xxxx() -->end() experience time: "
* @param logLevel Log输出级别,1:i; 2:w;3:e.
*/
public static void end(String logTag, String logExtraInfo, int logLevel) {
long endTiem = System.currentTimeMillis();
long wasteTiem = endTiem - startTime;
String finalLogTag = logTag == null ? TAG : logTag;
String logInfoContent = " --> waste time: "+ wasteTiem;
if (logExtraInfo != null) {
logInfoContent = logExtraInfo + logInfoContent;
}
switch (logLevel) {
case 1:
CommonLog.i(finalLogTag, logInfoContent);
break;
case 2:
CommonLog.w(finalLogTag, logInfoContent);
break;
case 3:
CommonLog.e(finalLogTag, logInfoContent);
break;
}
}
}