timing.java

来自「mallet是自然语言处理、机器学习领域的一个开源项目。」· Java 代码 · 共 67 行

JAVA
67
字号
/* Copyright (C) 2003 Univ. of Massachusetts Amherst, Computer Science Dept.   This file is part of "MALLET" (MAchine Learning for LanguagE Toolkit).   http://www.cs.umass.edu/~mccallum/mallet   This software is provided under the terms of the Common Public License,   version 1.0, as published by http://www.opensource.org.  For further   information, see the file `LICENSE' included with this distribution. */package edu.umass.cs.mallet.base.util;/** * A class for timing things. * Originally inspired by the Timing class in the Stanford NLP cade, * but completely rewritten. * <p/> * Created: Dec 30, 2004 * * @author <A HREF="mailto:casutton@cs.umass.edu>casutton@cs.umass.edu</A> * @version $Id: Timing.java,v 1.1 2005/06/01 22:27:35 casutton Exp $ */public class Timing {  private long objCreationTime;  private long startTime;  public Timing ()  {    startTime = System.currentTimeMillis ();    objCreationTime = startTime;  }  /**   * Print to System.out how much time has passed, resetting this Timing's start time to   * the current time.  Time is measured from the most recent   * <code>tick</code> call, or when this object was created.   *   * @param msg Prefix of string printed with time   * @return Number of elapsed milliseconds from tick (or start)   */  public long tick (String msg)  {    long currentTime = System.currentTimeMillis ();    long elapsed = currentTime - startTime;    startTime = currentTime;    System.out.println (msg + " time (ms) =  " + (elapsed));    return elapsed;  }  /**   * Returns how much time as passed since Object creation, or the most recent call to tick().   * @return Number of elapsed milliseconds   */  public long elapsedTime ()  {    return System.currentTimeMillis () - startTime;  }  /**   * Returns the number of milliseconds since this object was created.   * Ignores previous calls to <tt>tick</tt>, unlike   * <tt>elapsedTime</tt> and <tt>tick</tt>.   */  public long totalElapsedTime ()  {    return System.currentTimeMillis () - objCreationTime;  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?