Skip to content

Class Stopper

Ori Roth edited this page Apr 2, 2017 · 3 revisions

###Synopsis of Class Stopper ###

public class Stopper { 
    /*
     * Forge (2)
     */
        Stopper(); 
        Stopper(String what); 
    /*
     * Type (7)
     */
        void stop(); 
        long peep(); 
        long time(); 
        void nextCase(); 
        int cases(); 
        String average(); 
        String toString(); 
    /*
     * Utilities (2)
     */
        static void mute(); 
        static void unmute(); 
} 

Code

// SSDLPedia
package il.ac.technion.cs.ssdl.utils;

import il.ac.technion.cs.ssdl.stereotypes.Instantiable;

/**
 * A class serving as stopwatch for measuring runtime of programs. To start a
 * stop watch, create an instance of this class. Method #peep() can be
 * used to determine the time elapsed since creation, while method
 * #stop() can be used to stop the timer. Measurement is carried out in
 * milliseconds.
 * 
 * This class also provides the means for repeated measurements of the
 * phenomenon. To do that, call #nextCase() at the end of every
 * occurrence of the phenomenon. Function #average() then gives the
 * average time of each such occurrence.
 * 
 * Author: Yossi Gil,
 * See:  18/06/2008
 */
@Instantiable public class Stopper {
    /**
     * Create a new instance
     */
    public Stopper() {
        this(null);
    }
    
    /**
     * Create a new instance distinguishable by a descriptive string, and print
     * a log message.
     * 
     * what a textual description of this instance, used in printouts
     */
    public Stopper(final String what) {
        this.what = what;
        if (what != null)
            out("Started " + what);
        begin = System.currentTimeMillis();
    }
    
    /**
     * Stop the timer, and print a log message with the time elapsed since
     * creation.
     */
    public void stop() {
        time = System.currentTimeMillis() - begin;
        out("Finished " + what + ": " + time + "ms");
    }
    
    /**
     * Return: the time elapsed since creation.
     */
    public long peep() {
        return System.currentTimeMillis() - begin;
    }
    
    /**
     * Stop the stopper (if it was not stopped already), and return the time
     * recorded on it.
     * 
     * Return: the time recorded on the stopper when it was stopped.
     */
    public long time() {
        if (time != 0)
            return time;
        time = System.currentTimeMillis() - begin;
        return time;
    }
    
    /**
     * Used for measuring multiple (similar) events with the same stopper, this
     * method records a new case.
     */
    public void nextCase() {
        cases++;
    }
    
    /**
     * Return: the number of cases recorded so far.
     */
    public int cases() {
        return cases;
    }
    
    /**
     * Return: the time since creation, per cases.
     */
    public String average() {
        return (double) peep() / cases / 1000.0 + " sec";
    }
    
    @Override public String toString() {
        return peep() / 1000.0 + " sec";
    }
    
    /**
     * Silence all stoppers from now on.
     */
    public static void mute() {
        mute = true;
    }
    
    /**
     * Allow stoppers to print their output from now on.
     */
    public static void unmute() {
        mute = false;
    }
    
    private static void out(final String m) {
        if (!mute)
            System.err.println(m);
    }
    
    private static boolean mute = false;
    private final long begin;
    private int cases = 1;
    private long time;
    private final String what;
}

Metrics

Metric Value Acronym Explanation
LOC 122 Lines Of Code Total number of lines in the code
SCC 24 SemiColons Count Total number of semicolon tokens found in the code.
NOT 290 Number Of Tokens Comments, whitespace and text which cannot be made into a token not included.
VCC 2188 Visible Characters Count The total number of non-white (i.e., not space, tab, newline, carriage return, form feed) characters.
CCC 932 Code Characters Count Total number of non-white characters in tokens. White space characters in string and character literals are not counted.
UIC 27 Unique Identifiers Count The number of different identifiers found in the code
WHC 3 Weighted Horizontal Complexity A heuritistic on horizontal complexity

Statistics

Statistic Value
Average token length 3.2
Tokens/line 2.4
Visible characters/line 18
Code characters/line 7.6
Semicolons/tokens 8%
Comment text percentage 57%

Tokens by kind

Token Kind Occurrences
KEYWORD 58
OPERATOR 25
LITERAL 10
ID 77
PUNCTUATION 120
COMMENT 12
OTHER 181
Clone this wiki locally