All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.xkzhangsan.time.cost.NanosecondCost Maven / Gradle / Ivy

Go to download

xk-time is a datetime converter calculator and formatter tool set, based on java8 date and time API, thread safe, easy to use.

There is a newer version: 3.2.4
Show newest version
package com.xkzhangsan.time.cost;

/**
 * 计算耗时,单位纳秒
* * @author xkzhangsan */ public final class NanosecondCost implements Cost{ private final String name; private final long nanosecond; public NanosecondCost() { super(); this.name = ""; this.nanosecond = System.nanoTime(); } public NanosecondCost(String name) { super(); this.name = name; this.nanosecond = System.nanoTime(); } @Override public long stop() { return System.nanoTime() - nanosecond; } @Override public void stopAndPrint() { System.out.println(stopAndFormat()); } @Override public String stopAndFormat() { return (this.name + " cost: " + stop() + " ns"); } @Override public String stopAccurate() { return String.valueOf(stop()); } @Override public void stopAccurateAndPrint() { System.out.println(stopAccurateAndFormat()); } @Override public String stopAccurateAndFormat() { return stopAndFormat(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy