diff options
author | paltherr <paltherr@epfl.ch> | 2005-01-25 17:08:56 +0000 |
---|---|---|
committer | paltherr <paltherr@epfl.ch> | 2005-01-25 17:08:56 +0000 |
commit | 2cd85f1d31d933f84448bbcbc0a8cbd225cfbfe4 (patch) | |
tree | 2b900db68b0defb89ff37a8269a5e80e5dd0a269 /sources | |
parent | 80c6300d103adcc45e50b2c91c104c7c1ce6dfc3 (diff) | |
download | scala-2cd85f1d31d933f84448bbcbc0a8cbd225cfbfe4.tar.gz scala-2cd85f1d31d933f84448bbcbc0a8cbd225cfbfe4.tar.bz2 scala-2cd85f1d31d933f84448bbcbc0a8cbd225cfbfe4.zip |
- Added timers
Diffstat (limited to 'sources')
-rw-r--r-- | sources/scala/tools/util/AbstractTimer.java | 49 | ||||
-rw-r--r-- | sources/scala/tools/util/DummyTimer.java | 44 | ||||
-rw-r--r-- | sources/scala/tools/util/ReporterTimer.java | 39 | ||||
-rw-r--r-- | sources/scala/tools/util/Timer.java | 27 |
4 files changed, 159 insertions, 0 deletions
diff --git a/sources/scala/tools/util/AbstractTimer.java b/sources/scala/tools/util/AbstractTimer.java new file mode 100644 index 0000000000..6314023fe3 --- /dev/null +++ b/sources/scala/tools/util/AbstractTimer.java @@ -0,0 +1,49 @@ +/* ____ ____ ____ ____ ______ *\ +** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** +** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** +** /_____/\____/\___/\____/____/ ** +\* */ + +// $Id$ + +package scala.tools.util; + +import java.util.ArrayList; + +/** + * This abstract class implements the collection of timings. How the + * collected timings are issued has to be implemented in subclasses. + */ +public abstract class AbstractTimer implements Timer { + + //######################################################################## + // Private Fields + + /** A stack for maintaining start times */ + private final ArrayList starts = new ArrayList(); + + //######################################################################## + // Public Methods + + /** Issues a timing information (duration in milliseconds). */ + public abstract void issue(String message, long duration); + + /** Starts a new timer. */ + public void start() { + starts.add(new Long(System.currentTimeMillis())); + } + + /** Ends the current timer. */ + public void stop(String message) { + long stop = System.currentTimeMillis(); + long start = ((Long)starts.remove(starts.size() - 1)).longValue(); + issue(message, stop - start); + } + + /** Drops the current timer. */ + public void drop() { + starts.remove(starts.size() - 1); + } + + //######################################################################## +} diff --git a/sources/scala/tools/util/DummyTimer.java b/sources/scala/tools/util/DummyTimer.java new file mode 100644 index 0000000000..e16c44b6be --- /dev/null +++ b/sources/scala/tools/util/DummyTimer.java @@ -0,0 +1,44 @@ +/* ____ ____ ____ ____ ______ *\ +** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** +** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** +** /_____/\____/\___/\____/____/ ** +\* */ + +// $Id$ + +package scala.tools.util; + +import java.util.ArrayList; + +/** This class implements a timer that does nothing. */ +public class DummyTimer implements Timer { + + //######################################################################## + // Public Constants + + /** The unique instance of this class. */ + public static final DummyTimer object = new DummyTimer(); + + //######################################################################## + // Private Constructors + + /** Initializes this instance. */ + private DummyTimer() {} + + //######################################################################## + // Public Methods + + /** Starts a new timer. */ + public void start() { + } + + /** Ends the current timer. */ + public void stop(String message) { + } + + /** Drops the current timer. */ + public void drop() { + } + + //######################################################################## +} diff --git a/sources/scala/tools/util/ReporterTimer.java b/sources/scala/tools/util/ReporterTimer.java new file mode 100644 index 0000000000..77e91d290d --- /dev/null +++ b/sources/scala/tools/util/ReporterTimer.java @@ -0,0 +1,39 @@ +/* ____ ____ ____ ____ ______ *\ +** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** +** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** +** /_____/\____/\___/\____/____/ ** +\* */ + +// $Id$ + +package scala.tools.util; + +/** + * This class implements a timer that uses a Reporter to issue + * timings. + */ +public class ReporterTimer extends AbstractTimer { + + //######################################################################## + // Private Fields + + /** A reporter to report timing information */ + private final Reporter reporter; + + //######################################################################## + // Public Constructors + + public ReporterTimer(Reporter reporter) { + this.reporter = reporter; + } + + //######################################################################## + // Public Methods + + /** Issues a timing information (duration in milliseconds). */ + public void issue(String message, long duration) { + reporter.inform("[" + message + " in " + duration + "ms]"); + } + + //######################################################################## +} diff --git a/sources/scala/tools/util/Timer.java b/sources/scala/tools/util/Timer.java new file mode 100644 index 0000000000..df60d580ae --- /dev/null +++ b/sources/scala/tools/util/Timer.java @@ -0,0 +1,27 @@ +/* ____ ____ ____ ____ ______ *\ +** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** +** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** +** /_____/\____/\___/\____/____/ ** +\* */ + +// $Id$ + +package scala.tools.util; + +/** This interface provides methods to collect timings. */ +public interface Timer { + + //######################################################################## + // Public Methods + + /** Starts a new timer. */ + public void start(); + + /** Stops the current timer. */ + public void stop(String message); + + /** Drops the current timer. */ + public void drop(); + + //######################################################################## +} |