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

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

Introduction

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

Prototype

public Stopwatch stop() 

Source Link

Document

Stops the stopwatch.

Usage

From source file:cc.kave.commons.pointsto.evaluation.PointsToEvaluation.java

private static void generateUsages(List<PointsToAnalysisFactory> factories) {
    try {//from w ww.j av a2  s.co m
        Function<PointsToAnalysisFactory, UsageStore> usageStoreFactory = (PointsToAnalysisFactory factory) -> {
            try {
                return new ProjectUsageStore(USAGE_DEST.resolve(factory.getName()));
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        };

        DescentStrategy descentStrategy = new SimpleDescentStrategy();
        PointsToUsageGenerator generator = new PointsToUsageGenerator(factories, SRC_PATH, null,
                usageStoreFactory, new TypeStatisticsCollector(new PointsToUsageFilter()), descentStrategy);

        Stopwatch stopwatch = Stopwatch.createStarted();
        generator.generateUsages();
        stopwatch.stop();
        LOGGER.info("Usage generation took {}", stopwatch.toString());

        outputStatisticsCollectors(generator.getStatisticsCollectors());

    } catch (IOException e) {
        LOGGER.error("Error during usage generation", e);
    }
}

From source file:com.android.messaging.util.GifTranscoder.java

public static boolean transcode(Context context, String filePath, String outFilePath) {
    if (!isEnabled()) {
        return false;
    }//  w  w w .jav a 2s .co  m
    final long inputSize = new File(filePath).length();
    Stopwatch stopwatch = Stopwatch.createStarted();
    final boolean success = transcodeInternal(filePath, outFilePath);
    stopwatch.stop();
    final long elapsedMs = stopwatch.elapsed(TimeUnit.MILLISECONDS);
    final long outputSize = new File(outFilePath).length();
    final float compression = (inputSize > 0) ? ((float) outputSize / inputSize) : 0;

    if (success) {
        LogUtil.i(TAG,
                String.format("Resized GIF (%s) in %d ms, %s => %s (%.0f%%)", LogUtil.sanitizePII(filePath),
                        elapsedMs, Formatter.formatShortFileSize(context, inputSize),
                        Formatter.formatShortFileSize(context, outputSize), compression * 100.0f));
    }
    return success;
}

From source file:com.persinity.common.fp.FunctionUtil.java

/**
 * @param f/*from  w  ww .  ja v a2s .co  m*/
 *         funciton to execute
 * @param arg
 *         argument to the function
 * @return Function Result, Stopwatch
 */
public static <T, E> DirectedEdge<E, Stopwatch> timeOf(final Function<T, E> f, final T arg) {
    notNull(f);

    Stopwatch stopwatch = Stopwatch.createStarted();
    E res;
    try {
        res = f.apply(arg);
    } finally {
        stopwatch.stop();
    }
    return new DirectedEdge<>(res, stopwatch);
}

From source file:com.christophbonitz.concurrent.Main.java

/**
 * Run with baseActorCount incrementors and decremntors, as well as 10*baseActorCount readers.
 * Each will perform actionsPerActor actions.
 * @param baseActorCount// w w  w  . ja va2s  . c o  m
 * @param actionsPerActor
 * @param pool
 * @param counter
 * @return time used in milliseconds.
 */
private static long time(int baseActorCount, int actionsPerActor, ExecutorService pool, Counter counter) {
    Stopwatch sw = Stopwatch.createStarted();
    CounterExecutor counterExecutor = new CounterExecutor(pool, counter, 10 * baseActorCount, baseActorCount,
            baseActorCount, actionsPerActor);
    counterExecutor.run();
    sw.stop();
    return sw.elapsed(TimeUnit.MILLISECONDS);
}

From source file:com.topekalabs.threads.ThreadUtils.java

public static <T> void done(Collection<Future<T>> futures, long timeout, TimeUnit timeUnit)
        throws TimeoutException, InterruptedException, ExecutionException {
    long milliTimeout = MILLIS_UNIT.convert(timeout, timeUnit);
    long currentTimeout = milliTimeout;

    Stopwatch sw = Stopwatch.createUnstarted();

    for (Future<?> future : futures) {
        sw.start();/*from   w  w w. j ava2 s . c  om*/
        future.get(currentTimeout, MILLIS_UNIT);
        sw.stop();

        long elapsed = sw.elapsed(MILLIS_UNIT);

        if (elapsed > milliTimeout) {
            throw new TimeoutException("Exceeded timeout of " + milliTimeout + " milliseconds.");
        }

        currentTimeout = milliTimeout - elapsed;
    }
}

From source file:processing.MPCalculator.java

private static List<int[]> getPopularTags(BookmarkReader reader, int sampleSize, int limit) {
    List<int[]> tags = new ArrayList<int[]>();
    Stopwatch timer = new Stopwatch();
    timer.start();// www.  j  a  va  2  s . c o  m

    int[] tagIDs = getPopularTagList(reader, limit);

    timer.stop();
    long trainingTime = timer.elapsed(TimeUnit.MILLISECONDS);
    timer.reset();
    timer.start();
    for (int j = 0; j < sampleSize; j++) {
        tags.add(tagIDs);
    }
    timer.stop();
    long testTime = timer.elapsed(TimeUnit.MILLISECONDS);

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

From source file:eu.amidst.dynamic.learning.dynamic.DynamicLearningEngine.java

/**
 * Learns both the structure and parameters of the dynamic model.
 * @param dataStream a given {@link DataStream} of {@link DynamicDataInstance}s.
 * @return a {@link DynamicBayesianNetwork} object.
 *///from   w  w w.  j  a v a2s.  c  om
public static DynamicBayesianNetwork learnDynamicModel(DataStream<DynamicDataInstance> dataStream) {
    Stopwatch watch = Stopwatch.createStarted();
    DynamicDAG dag = dynamicStructuralLearningAlgorithm.learn(dataStream);
    System.out.println("Structural Learning : " + watch.stop());

    watch = Stopwatch.createStarted();
    DynamicBayesianNetwork network = dynamicParameterLearningAlgorithm.learn(dag, dataStream);
    System.out.println("Parameter Learning: " + watch.stop());

    return network;
}

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  .ja v a  2  s .  c o  m*/
            "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: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);

    }//from  w ww.  j a  va2  s  .  c  om
    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.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 w w  w.  j a v a2 s . c  o  m*/
    sw.stop();

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

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

}