From d6c29e8757422856b86157e4b550cb0f8d3a23c2 Mon Sep 17 00:00:00 2001 From: 502647092 Date: Sun, 30 Jul 2017 20:24:13 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E6=80=A7=E8=83=BD?= =?UTF-8?q?=E6=A3=80=E6=B5=8B=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 502647092 --- .../java/pw/yumc/YumCore/misc/Timings.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/main/java/pw/yumc/YumCore/misc/Timings.java diff --git a/src/main/java/pw/yumc/YumCore/misc/Timings.java b/src/main/java/pw/yumc/YumCore/misc/Timings.java new file mode 100644 index 0000000..84cb959 --- /dev/null +++ b/src/main/java/pw/yumc/YumCore/misc/Timings.java @@ -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 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()); + } +}