mirror of
https://e.coding.net/circlecloud/YumCore.git
synced 2024-11-24 02:08:48 +00:00
feat: 添加性能检测工具
Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
parent
2829e298d5
commit
d6c29e8757
44
src/main/java/pw/yumc/YumCore/misc/Timings.java
Normal file
44
src/main/java/pw/yumc/YumCore/misc/Timings.java
Normal file
@ -0,0 +1,44 @@
|
||||
package pw.yumc.YumCore.misc;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import pw.yumc.YumCore.bukkit.Log;
|
||||
|
||||
/**
|
||||
* 性能检测类
|
||||
* Created by 蒋天蓓 on 2017/2/9 0009.
|
||||
*/
|
||||
public class Timings {
|
||||
private static Map<String, Timings> timingsMap = new WeakHashMap<>();
|
||||
private String name;
|
||||
private long start;
|
||||
|
||||
public Timings(String name) {
|
||||
this.name = name;
|
||||
this.start = System.nanoTime();
|
||||
}
|
||||
|
||||
public static Timings get(String string) {
|
||||
if (!timingsMap.containsKey(string)) {
|
||||
timingsMap.put(string, new Timings(string));
|
||||
}
|
||||
return timingsMap.get(string);
|
||||
}
|
||||
|
||||
public static Timings clear(String string) {
|
||||
return timingsMap.remove(string);
|
||||
}
|
||||
|
||||
public void start() {
|
||||
this.start = System.nanoTime();
|
||||
}
|
||||
|
||||
public double stop() {
|
||||
return (System.nanoTime() - start) / 1024.00 / 1024.00;
|
||||
}
|
||||
|
||||
public void print() {
|
||||
Log.d("操作 %s 耗时 %sms", name, stop());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user