/*
* Copyright (C) 2008 The Guava Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.common.base;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static java.util.concurrent.TimeUnit.MICROSECONDS;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.NANOSECONDS;
import static java.util.concurrent.TimeUnit.SECONDS;
import com.google.common.annotations.Beta;
import com.google.common.annotations.GwtCompatible;
import com.google.common.annotations.GwtIncompatible;
import java.util.concurrent.TimeUnit;
/**
* An object that measures elapsed time in nanoseconds. It is useful to measure
* elapsed time using this class instead of direct calls to {@link
* System#nanoTime} for a few reasons:
*
* <ul>
* <li>An alternate time source can be substituted, for testing or performance
* reasons.
* <li>As documented by {@code nanoTime}, the value returned has no absolute
* meaning, and can only be interpreted as relative to another timestamp
* returned by {@code nanoTime} at a different time. {@code Stopwatch} is a
* more effective abstraction because it exposes only these relative values,
* not the absolute ones.
* </ul>
*
* <p>Basic usage:
* <pre>
* Stopwatch stopwatch = new Stopwatch().{@link #start start}();
* doSomething();
* stopwatch.{@link #stop stop}(); // optional
*
* long millis = stopwatch.{@link #elapsedMillis elapsedMillis}();
*
* log.info("that took: " + stopwatch); // formatted string like "12.3 ms"
* </pre>
*
* <p>Stopwatch methods are not idempotent; it is an error to start or stop a
* stopwatch that is already in the desired state.
*
* <p>When testing code that uses this class, use the {@linkplain
* #Stopwatch(Ticker) alternate constructor} to supply a fake or mock ticker.
* <!-- TODO(kevinb): restore the "such as" --> This allows you to
* simulate any valid behavior of the stopwatch.
*
* <p><b>Note:</b> This class is not thread-safe.
*
* @author Kevin Bourrillion
* @since 10.0
*/
@Beta
@GwtCompatible(emulated=true)
public final class Stopwatch {
private final Ticker ticker;
private boolean isRunning;
private long elapsedNanos;
private long startTick;
public long elapsed(TimeUnit desiredUnit) {
return desiredUnit.convert(elapsedNanos(), NANOSECONDS);
}
/**
* Creates (but does not start) a new stopwatch using {@link System#nanoTime}
* as its time source.
*
* @since 15.0
*/
public static Stopwatch createUnstarted() {
return new Stopwatch();
}
/**
* Creates (but does not start) a new stopwatch, using the specified time
* source.
*
* @since 15.0
*/
public static Stopwatch createUnstarted(Ticker ticker) {
return new Stopwatch(ticker);
}
/**
* Creates (but does not start) a new stopwatch using {@link System#nanoTime}
* as its time source.
*/
public Stopwatch() {
this(Ticker.systemTicker());
}
/**
* Creates (but does not start) a new stopwatch, using the specified time
* source.
*/
public Stopwatch(Ticker ticker) {
this.ticker = checkNotNull(ticker);
}
/**
* Returns {@code true} if {@link #start()} has been called on this stopwatch,
* and {@link #stop()} has not been called since the last call to {@code
* start()}.
*/
public boolean isRunning() {
return isRunning;
}
/**
* Starts the stopwatch.
*
* @return this {@code Stopwatch} instance
* @throws IllegalStateException if the stopwatch is already running.
*/
public Stopwatch start() {
checkState(!isRunning);
isRunning = true;
startTick = ticker.read();
return this;
}
/**
* Stops the stopwatch. Future reads will return the fixed duration that had
* elapsed up to this point.
*
* @return this {@code Stopwatch} instance
* @throws IllegalStateException if the stopwatch is already stopped.
*/
public Stopwatch stop() {
long tick = ticker.read();
checkState(isRunning);
isRunning = false;
elapsedNanos += tick - startTick;
return this;
}
/**
* Sets the elapsed time for this stopwatch to zero,
* and places it in a stopped state.
*
* @return this {@code Stopwatch} instance
*/
public Stopwatch reset() {
elapsedNanos = 0;
isRunning = false;
return this;
}
private long elapsedNanos() {
return isRunning ? ticker.read() - startTick + elapsedNanos : elapsedNanos;
}
/**
* Returns the current elapsed time shown on this stopwatch, expressed
* in the desired time unit, with any fraction rounded down.
*
* <p>Note that the overhead of measurement can be more than a microsecond, so
* it is generally not useful to specify {@link TimeUnit#NANOSECONDS}
* precision here.
*/
public long elapsedTime(TimeUnit desiredUnit) {
return desiredUnit.convert(elapsedNanos(), NANOSECONDS);
}
/**
* Returns the current elapsed time shown on this stopwatch, expressed
* in milliseconds, with any fraction rounded down. This is identical to
* {@code elapsedTime(TimeUnit.MILLISECONDS}.
*/
public long elapsedMillis() {
return elapsedTime(MILLISECONDS);
}
/**
* Returns a string representation of the current elapsed time; equivalent to
* {@code toString(4)} (four significant figures).
*/
@GwtIncompatible("String.format()")
@Override public String toString() {
return toString(4);
}
/**
* Returns a string representation of the current elapsed time, choosing an
* appropriate unit and using the specified number of significant figures.
* For example, at the instant when {@code elapsedTime(NANOSECONDS)} would
* return {1234567}, {@code toString(4)} returns {@code "1.235 ms"}.
*/
@GwtIncompatible("String.format()")
public String toString(int significantDigits) {
long nanos = elapsedNanos();
TimeUnit unit = chooseUnit(nanos);
double value = (double) nanos / NANOSECONDS.convert(1, unit);
// Too bad this functionality is not exposed as a regular method call
return String.format("%." + significantDigits + "g %s",
value, abbreviate(unit));
}
private static TimeUnit chooseUnit(long nanos) {
if (SECONDS.convert(nanos, NANOSECONDS) > 0) {
return SECONDS;
}
if (MILLISECONDS.convert(nanos, NANOSECONDS) > 0) {
return MILLISECONDS;
}
if (MICROSECONDS.convert(nanos, NANOSECONDS) > 0) {
return MICROSECONDS;
}
return NANOSECONDS;
}
private static String abbreviate(TimeUnit unit) {
switch (unit) {
case NANOSECONDS:
return "ns";
case MICROSECONDS:
return "\u03bcs"; // μs
case MILLISECONDS:
return "ms";
case SECONDS:
return "s";
default:
throw new AssertionError();
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
一种基于预训练大语言模型与深度知识图谱的健康信息推荐系统 1、集群:三台Centos6.5虚拟机,搭建的ElasticSearch和HBase集群 2、Maven构建的spring工程: create.do:创建索引,先后在HBase和ElasticSearch中创建索引 search.do:搜索 3、基于jdk1.7,Tomcat7.0 该项目可以达到亿万级索引的秒级甚至毫秒级的搜索速度
资源推荐
资源详情
资源评论
收起资源包目录
人工智能-项目实践-搜索引擎-一种基于预训练大语言模型与深度知识图谱的健康信息推荐系统 (293个子文件)
HbaseUtils.class 10KB
HbaseUtils.class 10KB
Esutil.class 8KB
Esutil.class 8KB
Testes.class 5KB
Testes.class 5KB
PageUtil.class 5KB
PageUtil.class 5KB
Index.class 4KB
Index.class 4KB
EsController.class 4KB
EsController.class 4KB
Stopwatch.class 4KB
Stopwatch.class 4KB
Doc.class 1KB
Doc.class 1KB
Stopwatch$1.class 854B
Stopwatch$1.class 854B
es_hbase_new.iml 12KB
elasticsearch-2.4.0.jar 9.04MB
elasticsearch-2.2.0.jar 8.9MB
hbase-protocol-1.1.3.jar 4.04MB
hadoop-common-2.5.1.jar 2.83MB
lucene-core-5.5.2.jar 2.26MB
lucene-core-5.4.1.jar 2.25MB
guava-18.0.jar 2.15MB
aspectjweaver-1.7.1.jar 1.71MB
netty-all-4.0.23.Final.jar 1.7MB
hadoop-yarn-api-2.5.1.jar 1.57MB
commons-math3-3.1.1.jar 1.53MB
lucene-analyzers-common-5.4.1.jar 1.5MB
lucene-analyzers-common-5.5.2.jar 1.5MB
hadoop-mapreduce-client-core-2.5.1.jar 1.43MB
htrace-core-3.1.0-incubating.jar 1.41MB
hadoop-yarn-common-2.5.1.jar 1.35MB
netty-3.10.5.Final.jar 1.27MB
netty-3.10.6.Final.jar 1.23MB
jcodings-1.0.8.jar 1.23MB
hbase-client-1.1.3.jar 1.2MB
hppc-0.7.1.jar 1.09MB
snappy-java-1.0.4.1.jar 973KB
spring-core-3.2.0.RELEASE.jar 843KB
spring-context-3.2.0.RELEASE.jar 834KB
zookeeper-3.4.6.jar 774KB
jackson-mapper-asl-1.9.13.jar 762KB
apacheds-kerberos-codec-2.0.0-M15.jar 675KB
spring-webmvc-3.2.0.RELEASE.jar 621KB
joda-time-2.9.4.jar 615KB
spring-web-3.2.0.RELEASE.jar 610KB
joda-time-2.8.2.jar 607KB
spring-beans-3.2.0.RELEASE.jar 591KB
commons-collections-3.2.2.jar 575KB
hbase-common-1.1.3.jar 523KB
protobuf-java-2.5.0.jar 521KB
log4j-1.2.17.jar 478KB
spring-test-3.2.0.RELEASE.jar 441KB
httpclient-4.2.5.jar 423KB
lucene-backward-codecs-5.4.1.jar 421KB
lucene-backward-codecs-5.5.2.jar 421KB
jstl-1.2.jar 405KB
lucene-queryparser-5.4.1.jar 393KB
lucene-queryparser-5.5.2.jar 393KB
spring-jdbc-3.2.0.RELEASE.jar 392KB
standard-1.1.2.jar 384KB
spring-orm-3.2.0.RELEASE.jar 383KB
spring-aop-3.2.0.RELEASE.jar 327KB
jackson-dataformat-yaml-2.6.2.jar 313KB
commons-httpclient-3.1.jar 298KB
avro-1.7.4.jar 296KB
commons-configuration-1.6.jar 292KB
commons-lang-2.6.jar 278KB
jackson-core-2.8.1.jar 273KB
lucene-sandbox-5.4.1.jar 267KB
commons-net-3.1.jar 267KB
snakeyaml-1.15.jar 263KB
commons-codec-1.9.jar 258KB
lucene-spatial-5.5.2.jar 255KB
jackson-core-2.6.2.jar 253KB
lucene-queries-5.5.2.jar 246KB
lucene-queries-5.4.1.jar 242KB
lucene-suggest-5.4.1.jar 240KB
lucene-suggest-5.5.2.jar 240KB
commons-compress-1.4.1.jar 236KB
spring-tx-3.2.0.RELEASE.jar 235KB
junit-4.8.jar 231KB
lucene-sandbox-5.5.2.jar 227KB
jackson-core-asl-1.9.13.jar 227KB
httpcore-4.2.4.jar 222KB
commons-beanutils-core-1.8.0.jar 201KB
lucene-spatial3d-5.5.2.jar 193KB
lucene-spatial3d-5.4.1.jar 192KB
lucene-spatial-5.4.1.jar 190KB
spring-expression-3.2.0.RELEASE.jar 189KB
commons-beanutils-1.7.0.jar 184KB
joni-2.1.2.jar 183KB
jsch-0.1.42.jar 181KB
commons-io-2.4.jar 181KB
jetty-util-6.1.26.jar 173KB
lucene-misc-5.4.1.jar 168KB
lucene-misc-5.5.2.jar 168KB
共 293 条
- 1
- 2
- 3
资源评论
博士僧小星
- 粉丝: 1745
- 资源: 5850
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 信息办公个人求职管理系统-jobgljsp.rar
- 信息办公一流网络JSP网络管理系统 v1.0-yljsp10.rar
- chirpstack学习
- 管家婆辉煌、财贸、工贸、服装,食品,千方模拟狗
- 基于python开发的工业环境老鼠检测+源码+文档(毕业设计&课程设计&项目开发)
- USB转以太网的芯片SR9900全套设计资料包括(参考设计原理图PCB+ Linux -Windows驱动程序+量产工具)
- 信息办公XML考试系统-xmlks.rar
- 基于python开发的无人机图像目标检测+实验数据+开发文档+操作流程+源码(毕业设计&课程设计&项目开发)
- 全球智能商品管理与优化系统
- IDM下载器(电脑小工具)
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功