Tim the Timer
From charlesreid1
Notes
This page contains Tim the Timer, a little timing object for Java that wraps calls to the system library. It can accumulate time and report the aggregate total, allowing it to be switched on and off only when operations of interest are being performed.
Code
/** * Tim the timer. * * "Hi Tim!" * "How much Tim - " * * Tim tim = new Tim(); * do stuff * tim.elapsedms() */ public class Tim { double cumulativeTotal, start, end; public Tim() { cumulativeTotal = 0.0; start = 0.0; end = 0.0;; } public void tic() { this.start = System.currentTimeMillis(); } public void toc() { this.end = System.currentTimeMillis(); cumulativeTotal += (end-start); } public double elapsedms() { return cumulativeTotal; } }
Flags
Computer Science notes on computer science topics on the wiki, for educational and learning purposes
Part of the 2017 CS Study Plan.
Python/Exceptions · Python/Assertions · Python/Decorators Python/Os (os module) · Python/Strings Python/Splat · Python/Iterators · Python/Generators Python/Comparators · Python/Lambdas
Builtin features of Java: Java/Exceptions · Java/Assertions · Java/Memory · Java/Interfaces Java/Generics · Java/Decorators · Java/Diamond Notation Java/Iterators · Java/Iterable · Iterators vs Iterable Java/Comparators · Java/Comparable · Comparators vs Comparable Java/Numeric · Java/TypeChecking · Java/Testing · Java/Timing · Java/Profiling Documentation: Javadocs · Java/Documentation Tools and functionality: Java/URLs · Java/CSV External libraries: Guava · Fastutil · Eclipse Collections OOP: OOP Checklist · Java/Abstract Class · Java/Encapsulation · Java/Generics
|
See also: