package edu.princeton.cs.introcs; /************************************************************************* * Compilation: javac Stopwatch.java * * *************************************************************************/ /** * <i>Stopwatch</i>. This class is a data type for measuring * the running time (wall clock) of a program. * <p> * For additional documentation, see * <a href="http://introcs.cs.princeton.edu/32class">Section 3.2</a> of * <i>Introduction to Programming in Java: An Interdisciplinary Approach</i> * by Robert Sedgewick and Kevin Wayne. */ public class Stopwatch { private final long start; /** * Create a stopwatch object. */ public Stopwatch() { start = System.currentTimeMillis(); } /** * Return elapsed time (in seconds) since this object was created. */ public double elapsedTime() { long now = System.currentTimeMillis(); return (now - start) / 1000.0; } } /************************************************************************* * Copyright 2002-2012, Robert Sedgewick and Kevin Wayne. * * This file is part of stdlib-package.jar, which accompanies the textbook * * Introduction to Programming in Java: An Interdisciplinary Approach * by R. Sedgewick and K. Wayne, Addison-Wesley, 2007. ISBN 0-321-49805-4. * * http://introcs.cs.princeton.edu * * * stdlib-package.jar is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * stdlib-package.jar is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with stdlib-package.jar. If not, see http://www.gnu.org/licenses. *************************************************************************/