public class CostUtil extends Object
包括:
1.计算耗时,返回耗时结果
Cost cost = CostUtil.startMillisecondCost();
TimeUnit.MILLISECONDS.sleep(1000);
long millisecond = cost.stop();
2.计算耗时,自定义任务名称,输出耗时结果
Cost cost = CostUtil.startMillisecondCost("millisecondCostTest");
TimeUnit.MILLISECONDS.sleep(1000);
cost.stopAndPrint();
// millisecondCostTest cost: 1000 ms
3.计算耗时,返回精确计时,带3小数的结果,使用ROUND_DOWN 舍弃超过3位的小数部分
Cost cost = CostUtil.startMillisecondCost();
TimeUnit.NANOSECONDS.sleep(1000_500_000);
cost.stopAccurate();
// 1001.238
| 限定符和类型 | 方法和说明 |
|---|---|
static Cost |
startMillisecondCost()
开始计时,单位毫秒,返回cost对象
|
static Cost |
startMillisecondCost(String name)
开始计时,单位毫秒,返回cost对象
|
static Cost |
startNanosecondCost()
开始计时,单位纳秒,返回cost对象
|
static Cost |
startNanosecondCost(String name)
开始计时,单位纳秒,返回cost对象
|
static Cost |
startSecondCost()
开始计时,单位秒,返回cost对象
|
static Cost |
startSecondCost(String name)
开始计时,单位秒,返回cost对象
|
public static Cost startNanosecondCost()
public static Cost startNanosecondCost(String name)
name - 任务名称public static Cost startMillisecondCost()
public static Cost startMillisecondCost(String name)
name - 任务名称public static Cost startSecondCost()
Copyright © 2021. All rights reserved.