Ignore:
Timestamp:
2013-11-02T16:36:10+01:00 (10 years ago)
Author:
Don-vip
Message:

print duration of tests for performance evaluation

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r6313 r6354  
    11// License: GPL. For details, see LICENSE file.
    22package org.openstreetmap.josm.tools;
     3
     4import static org.openstreetmap.josm.tools.I18n.tr;
     5import static org.openstreetmap.josm.tools.I18n.trn;
    36
    47import java.awt.Color;
     
    754757        return josmTmpDir;
    755758    }
     759
     760    /**
     761     * Returns a simple human readable (hours, minutes, seconds) string for a given duration in milliseconds.
     762     * @param elapsedTime The duration in milliseconds
     763     * @return A human redable string for the given duration
     764     * @throws IllegalArgumentException if elapsedTime is < 0
     765     * @since 6354
     766     */
     767    public static String getDurationString(long elapsedTime) throws IllegalArgumentException {
     768        if (elapsedTime < 0) {
     769            throw new IllegalArgumentException("elapsedTime must be > 0");
     770        }
     771        // Is it less than 1 second ?
     772        if (elapsedTime < 1000) {
     773            return String.format("%d %s", elapsedTime, tr("ms"));
     774        }
     775        // Is it less than 1 minute ?
     776        if (elapsedTime < 60*1000) {
     777            return String.format("%.1f %s", elapsedTime/1000f, tr("s"));
     778        }
     779        // Is it less than 1 hour ?
     780        if (elapsedTime < 60*60*1000) {
     781            return String.format("%d %s %d %s", elapsedTime/60000, tr("min"), elapsedTime/1000, tr("s"));
     782        }
     783        // Is it less than 1 day ?
     784        if (elapsedTime < 24*60*60*1000) {
     785            return String.format("%d %s %d %s", elapsedTime/3600000, tr("h"), elapsedTime/60000, tr("min"));
     786        }
     787        long days = elapsedTime/86400000;
     788        return String.format("%d %s %d %s", days, trn("day", "days", days), elapsedTime/3600000, tr("h"));
     789    }
    756790}
Note: See TracChangeset for help on using the changeset viewer.