Example usage for com.google.common.base Stopwatch elapsed

List of usage examples for com.google.common.base Stopwatch elapsed

Introduction

In this page you can find the example usage for com.google.common.base Stopwatch elapsed.

Prototype

@CheckReturnValue
public long elapsed(TimeUnit desiredUnit) 

Source Link

Document

Returns the current elapsed time shown on this stopwatch, expressed in the desired time unit, with any fraction rounded down.

Usage

From source file:org.glowroot.agent.it.harness.Threads.java

public static void moreAccurateSleep(long millis) throws InterruptedException {
    Stopwatch stopwatch = Stopwatch.createStarted();
    if (millis > 10) {
        MILLISECONDS.sleep(millis - 10);
    }/*from   w  w  w .  j  av  a  2s . com*/
    while (stopwatch.elapsed(MILLISECONDS) < millis) {
        MILLISECONDS.sleep(1);
    }
}

From source file:com.comphenix.blockpatcher.Calculations.java

public static double getMilliseconds(Stopwatch watch) {
    return watch.elapsed(TimeUnit.NANOSECONDS) / 1000000.0;
}

From source file:org.apache.bookkeeper.tests.integration.cluster.BookKeeperClusterTestBase.java

protected static void waitUntilBookieUnregistered(String bookieName) throws Exception {
    Stopwatch sw = Stopwatch.createStarted();
    while (findIfBookieRegistered(bookieName)) {
        TimeUnit.MILLISECONDS.sleep(1000);
        log.info("Bookie {} is still registered in cluster {} after {} ms elapsed", bookieName,
                bkCluster.getClusterName(), sw.elapsed(TimeUnit.MILLISECONDS));
    }/*from  ww w.  j a  v a  2s . c  om*/
}

From source file:org.simmetrics.performance.BatchPerformance.java

private static void testCompareCached() {

    StringMetric metric = new StringMetricBuilder().with(new SimonWhite<String>())
            .tokenize(new WhitespaceTokenizer()).tokenize(new QGramTokenizer(2)).setTokenizerCache().build();

    Stopwatch sw = Stopwatch.createStarted();
    for (int n = 0; n < TEST_REPEATS; n++) {
        @SuppressWarnings("unused")
        final float[] results = compare(metric, name, names);

    }/*from ww w . ja  v a 2 s .c  om*/
    sw.stop();

    String message = "Cached performance %s ms. Repeats %s";

    System.out.println(String.format(message, sw.elapsed(TimeUnit.MILLISECONDS), TEST_REPEATS));

}

From source file:org.simmetrics.performance.BatchPerformance.java

private static void testCompareUncached() {
    StringMetric metric = new StringMetricBuilder().with(new SimonWhite<String>())
            .tokenize(new WhitespaceTokenizer()).tokenize(new QGramTokenizer(2)).build();

    Stopwatch sw = Stopwatch.createStarted();
    for (int n = 0; n < TEST_REPEATS; n++) {
        @SuppressWarnings("unused")
        final float[] results = compare(metric, name, names);

    }//  www. jav  a 2s  . co  m
    sw.stop();

    String message = "Uncached performance %s ms. Repeats %s.";

    System.out.println(String.format(message, sw.elapsed(TimeUnit.MILLISECONDS), TEST_REPEATS));

}

From source file:org.catrobat.catroid.common.bluetooth.ConnectionDataLogger.java

private static byte[] getNextMessage(BlockingQueue<byte[]> messages, int messageOffset, int messageByteOffset) {

    Stopwatch stopWatch = Stopwatch.createStarted();

    for (int i = 0; i < messageOffset; i++) {
        byte[] message = pollMessage(messages, TIMEOUT_SECONDS - (int) stopWatch.elapsed(TimeUnit.SECONDS));
        if (message == null) {
            return null;
        }/*  ww w.j  a  va  2 s  . co  m*/
    }

    byte[] message = pollMessage(messages, TIMEOUT_SECONDS - (int) stopWatch.elapsed(TimeUnit.SECONDS));
    if (message == null) {
        return null;
    }

    return BluetoothTestUtils.getSubArray(message, messageByteOffset);
}

From source file:processing.MPurCalculator.java

public static List<Map<Integer, Double>> startLanguageModelCreation(BookmarkReader reader, int sampleSize,
        boolean sorting, boolean userBased, boolean resBased, int beta) {
    int size = reader.getBookmarks().size();
    int trainSize = size - sampleSize;

    Stopwatch timer = new Stopwatch();
    timer.start();//from   w w w  .  jav  a 2 s .c o  m
    MPurCalculator calculator = new MPurCalculator(reader, trainSize, beta, userBased, resBased);
    timer.stop();
    long trainingTime = timer.elapsed(TimeUnit.MILLISECONDS);
    List<Map<Integer, Double>> results = new ArrayList<Map<Integer, Double>>();
    if (trainSize == size) {
        trainSize = 0;
    }

    timer.reset();
    timer.start();
    for (int i = trainSize; i < size; i++) { // the test-set
        Bookmark data = reader.getBookmarks().get(i);
        Map<Integer, Double> map = calculator.getRankedTagList(data.getUserID(), data.getResourceID(), sorting);
        results.add(map);
    }
    timer.stop();
    long testTime = timer.elapsed(TimeUnit.MILLISECONDS);

    timeString = PerformanceMeasurement.addTimeMeasurement(timeString, true, trainingTime, testTime,
            sampleSize);
    return results;
}

From source file:com.altoukhov.svsync.engines.Syncer.java

private static void writeFile(IReadableFileSpace source, IWriteableFileSpace target, FileSnapshot file) {

    System.out.println(//from ww w.j  a v a 2s. c  om
            "Writing file " + file.getRelativePath() + ", " + Utils.readableFileSize(file.getFileSize()));

    Stopwatch stopwatch = Stopwatch.createStarted();
    boolean success = target.writeFile(source.readFile(file.getRelativePath()), file);
    stopwatch.stop();

    if (success) {
        System.out.println("Write speed was "
                + Utils.readableTransferRate(file.getFileSize(), stopwatch.elapsed(TimeUnit.MILLISECONDS))
                + "/s");
    } else {
        System.out.println("Failed to write file " + file.getRelativePath());
    }
}

From source file:processing.LanguageModelCalculator.java

public static List<Map<Integer, Double>> startLanguageModelCreation(BookmarkReader reader, int sampleSize,
        boolean sorting, boolean userBased, boolean resBased, int beta, boolean smoothing) {
    timeString = "";
    int size = reader.getUserLines().size();
    int trainSize = size - sampleSize;

    Stopwatch timer = new Stopwatch();
    timer.start();/*from   w w  w .j a va 2s.c  o  m*/
    LanguageModelCalculator calculator = new LanguageModelCalculator(reader, trainSize, beta, userBased,
            resBased);
    timer.stop();
    long trainingTime = timer.elapsed(TimeUnit.MILLISECONDS);
    List<Map<Integer, Double>> results = new ArrayList<Map<Integer, Double>>();
    if (trainSize == size) {
        trainSize = 0;
    }

    timer = new Stopwatch();
    timer.start();
    for (int i = trainSize; i < size; i++) { // the test-set
        UserData data = reader.getUserLines().get(i);
        Map<Integer, Double> map = calculator.getRankedTagList(data.getUserID(), data.getWikiID(), sorting,
                smoothing);
        results.add(map);
    }
    timer.stop();
    long testTime = timer.elapsed(TimeUnit.MILLISECONDS);
    timeString += ("Full training time: " + trainingTime + "\n");
    timeString += ("Full test time: " + testTime + "\n");
    timeString += ("Average test time: " + testTime / (double) sampleSize) + "\n";
    timeString += ("Total time: " + (trainingTime + testTime) + "\n");
    return results;
}

From source file:processing.LayersCalculator.java

public static void predictSample(String filename, int trainSize, int sampleSize, int beta) {
    //filename += "_res";
    BookmarkReader reader = new BookmarkReader(trainSize, false);
    reader.readFile(filename);/*from w ww.  jav  a 2  s .  c  o  m*/

    List<int[]> predictionValues = new ArrayList<int[]>();
    Stopwatch timer = new Stopwatch();
    timer.start();
    LayersCalculator calculator = new LayersCalculator(reader, trainSize, beta);
    timer.stop();
    long trainingTime = timer.elapsed(TimeUnit.MILLISECONDS);

    timer = new Stopwatch();
    timer.start();
    for (int i = trainSize; i < trainSize + sampleSize; i++) { // the test-set
        UserData data = reader.getUserLines().get(i);
        Map<Integer, Double> map = calculator.getRankedTagList(data.getUserID(), data.getWikiID(),
                data.getCategories());
        predictionValues.add(Ints.toArray(map.keySet()));
    }
    timer.stop();
    long testTime = timer.elapsed(TimeUnit.MILLISECONDS);
    timeString += ("Full training time: " + trainingTime + "\n");
    timeString += ("Full test time: " + testTime + "\n");
    timeString += ("Average test time: " + testTime / (double) sampleSize) + "\n";
    timeString += ("Total time: " + (trainingTime + testTime) + "\n");
    String outputFile = filename + "_3layers";
    Utilities.writeStringToFile("./data/metrics/" + outputFile + "_TIME.txt", timeString);

    reader.setUserLines(reader.getUserLines().subList(trainSize, reader.getUserLines().size()));
    PredictionFileWriter writer = new PredictionFileWriter(reader, predictionValues);
    writer.writeFile(outputFile);
}