Ignore:
Timestamp:
2020-01-23T22:57:46+01:00 (6 years ago)
Author:
simon04
Message:

Introduce Stopwatch class to measure elapsed time

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/DatasetConsistencyTest.java

    r12620 r15755  
    1010import org.openstreetmap.josm.tools.JosmRuntimeException;
    1111import org.openstreetmap.josm.tools.Logging;
    12 import org.openstreetmap.josm.tools.Utils;
     12import org.openstreetmap.josm.tools.Stopwatch;
    1313
    1414/**
     
    4646     */
    4747    public void checkReferrers() {
    48         long startTime = System.currentTimeMillis();
     48        final Stopwatch stopwatch = Stopwatch.createStarted();
    4949        // It's also error when referred primitive's dataset is null but it's already covered by referredPrimitiveNotInDataset check
    5050        for (Way way : dataSet.getWays()) {
     
    6767            }
    6868        }
    69         printElapsedTime(startTime);
     69        printElapsedTime(stopwatch);
    7070    }
    7171
     
    7474     */
    7575    public void checkCompleteWaysWithIncompleteNodes() {
    76         long startTime = System.currentTimeMillis();
     76        final Stopwatch stopwatch = Stopwatch.createStarted();
    7777        for (Way way : dataSet.getWays()) {
    7878            if (way.isUsable()) {
     
    8484            }
    8585        }
    86         printElapsedTime(startTime);
     86        printElapsedTime(stopwatch);
    8787    }
    8888
     
    9191     */
    9292    public void checkCompleteNodesWithoutCoordinates() {
    93         long startTime = System.currentTimeMillis();
     93        final Stopwatch stopwatch = Stopwatch.createStarted();
    9494        for (Node node : dataSet.getNodes()) {
    9595            if (!node.isIncomplete() && node.isVisible() && !node.isLatLonKnown()) {
     
    9797            }
    9898        }
    99         printElapsedTime(startTime);
     99        printElapsedTime(stopwatch);
    100100    }
    101101
     
    104104     */
    105105    public void searchNodes() {
    106         long startTime = System.currentTimeMillis();
     106        final Stopwatch stopwatch = Stopwatch.createStarted();
    107107        dataSet.getReadLock().lock();
    108108        try {
     
    116116            dataSet.getReadLock().unlock();
    117117        }
    118         printElapsedTime(startTime);
     118        printElapsedTime(stopwatch);
    119119    }
    120120
     
    123123     */
    124124    public void searchWays() {
    125         long startTime = System.currentTimeMillis();
     125        final Stopwatch stopwatch = Stopwatch.createStarted();
    126126        dataSet.getReadLock().lock();
    127127        try {
     
    134134            dataSet.getReadLock().unlock();
    135135        }
    136         printElapsedTime(startTime);
     136        printElapsedTime(stopwatch);
    137137    }
    138138
     
    155155     */
    156156    public void referredPrimitiveNotInDataset() {
    157         long startTime = System.currentTimeMillis();
     157        final Stopwatch stopwatch = Stopwatch.createStarted();
    158158        for (Way way : dataSet.getWays()) {
    159159            for (Node node : way.getNodes()) {
     
    167167            }
    168168        }
    169         printElapsedTime(startTime);
     169        printElapsedTime(stopwatch);
    170170    }
    171171
     
    174174     */
    175175    public void checkZeroNodesWays() {
    176         long startTime = System.currentTimeMillis();
     176        final Stopwatch stopwatch = Stopwatch.createStarted();
    177177        for (Way way : dataSet.getWays()) {
    178178            if (way.isUsable() && way.getNodesCount() == 0) {
     
    182182            }
    183183        }
    184         printElapsedTime(startTime);
    185     }
    186 
    187     private void printElapsedTime(long startTime) {
     184        printElapsedTime(stopwatch);
     185    }
     186
     187    private void printElapsedTime(Stopwatch stopwatch) {
    188188        if (Logging.isDebugEnabled()) {
    189189            StackTraceElement item = Thread.currentThread().getStackTrace()[2];
    190190            String operation = getClass().getSimpleName() + '.' + item.getMethodName();
    191             long elapsedTime = System.currentTimeMillis() - startTime;
    192191            Logging.debug(tr("Test ''{0}'' completed in {1}",
    193                     operation, Utils.getDurationString(elapsedTime)));
     192                    operation, stopwatch));
    194193        }
    195194    }
     
    200199    public void runTest() {
    201200        try {
    202             long startTime = System.currentTimeMillis();
     201            final Stopwatch stopwatch = Stopwatch.createStarted();
    203202            referredPrimitiveNotInDataset();
    204203            checkReferrers();
     
    208207            searchWays();
    209208            checkZeroNodesWays();
    210             printElapsedTime(startTime);
     209            printElapsedTime(stopwatch);
    211210            if (errorCount > MAX_ERRORS) {
    212211                writer.println((errorCount - MAX_ERRORS) + " more...");
Note: See TracChangeset for help on using the changeset viewer.