List of usage examples for com.google.common.base Stopwatch elapsed
@CheckReturnValue public long elapsed(TimeUnit desiredUnit)
From source file:com.spotify.heroic.metric.ResultGroups.java
public static Transform<ResultGroups, ResultGroups> trace(final Identifier what) { final Stopwatch w = Stopwatch.createStarted(); return r -> new ResultGroups(r.groups, r.errors, r.statistics, new QueryTrace(what, w.elapsed(TimeUnit.NANOSECONDS), ImmutableList.of(r.trace))); }
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 . j av a 2 s . 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:edu.sdsc.scigraph.owlapi.loader.BatchOwlLoader.java
public static void load(OwlLoadConfiguration config) throws InterruptedException { Injector i = Guice.createInjector(new OwlLoaderModule(config), new Neo4jModule(config.getGraphConfiguration())); BatchOwlLoader loader = i.getInstance(BatchOwlLoader.class); loader.ontologies = config.getOntologies(); logger.info("Loading ontologies..."); Stopwatch timer = Stopwatch.createStarted(); loader.loadOntology();/*from w ww . j a v a 2s .c o m*/ logger.info(format("Loading took %d minutes", timer.elapsed(TimeUnit.MINUTES))); }
From source file:com.android.messaging.util.GifTranscoder.java
public static boolean transcode(Context context, String filePath, String outFilePath) { if (!isEnabled()) { return false; }//from w ww.j a v 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:org.asoem.greyfish.utils.collect.UnrolledListAT.java
protected static <T> long measureFindFirstUnrolled(final FunctionalList<T> list, final Iterable<? extends Predicate<? super T>> predicates) { final Stopwatch stopwatch = Stopwatch.createStarted(); for (Predicate<? super T> predicate : predicates) { list.findFirst(predicate);// www . j av a 2s. co m } return stopwatch.elapsed(TimeUnit.MICROSECONDS); }
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 a v a2 s .c o m*/ 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:org.opendaylight.protocol.pcep.pcc.mock.PCCMockCommon.java
private static void checkNumberOfMessages(final int expectedNMessages, final TestingSessionListener listener) throws Exception { Stopwatch sw = Stopwatch.createStarted(); while (sw.elapsed(TimeUnit.SECONDS) <= 10) { if (expectedNMessages != listener.messages().size()) { Uninterruptibles.sleepUninterruptibly(50, TimeUnit.MILLISECONDS); } else {//www.jav a2 s .c o m return; } } Assert.assertEquals(expectedNMessages, listener.messages().size()); }
From source file:org.asoem.greyfish.utils.collect.UnrolledListAT.java
protected static <T> long measureFindFirstIterative(final List<T> list, final Iterable<? extends Predicate<? super T>> predicates) { final Stopwatch stopwatch = Stopwatch.createStarted(); for (Predicate<? super T> predicate : predicates) { findFirstIterative(list, predicate); }/*from w w w . j a v a 2 s. c om*/ return stopwatch.elapsed(TimeUnit.MICROSECONDS); }
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();// w w w.j a va2 s. c om 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:org.apache.geode.test.dunit.rules.DistributedDisconnectRule.java
public static void disconnect() { Stopwatch stopwatch = Stopwatch.createStarted(); InternalDistributedSystem system = InternalDistributedSystem.getConnectedInstance(); while (system != null && stopwatch.elapsed(MINUTES) < 10) { system = InternalDistributedSystem.getConnectedInstance(); try {//from w w w.j av a2 s. c o m system.disconnect(); } catch (Exception ignore) { // ignored } } AdminDistributedSystemImpl adminSystem = AdminDistributedSystemImpl.getConnectedInstance(); if (adminSystem != null) { adminSystem.disconnect(); } }