List of usage examples for com.google.common.base Stopwatch elapsed
@CheckReturnValue public long elapsed(TimeUnit desiredUnit)
From source file:com.dvdprime.server.mobile.servlet.GCMServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse res) { Stopwatch sw = new Stopwatch().start(); logger.log(Level.INFO, "Start GCM: {0}ms", sw.elapsed(TimeUnit.MILLISECONDS)); Notification.getNotificationList(); logger.log(Level.INFO, "End GCM: {0}ms", sw.elapsed(TimeUnit.MILLISECONDS)); }
From source file:org.apache.geode_examples.cq.Example.java
private void startPuttingData(Region region) throws InterruptedException { // Example will run for 20 second Stopwatch stopWatch = Stopwatch.createStarted(); while (stopWatch.elapsed(TimeUnit.SECONDS) < 20) { // 500ms delay to make this easier to follow Thread.sleep(500);//from w w w .j a v a2 s . c om int randomKey = ThreadLocalRandom.current().nextInt(0, 99 + 1); int randomValue = ThreadLocalRandom.current().nextInt(0, 100 + 1); region.put(randomKey, randomValue); System.out.println("Key: " + randomKey + " Value: " + randomValue); } stopWatch.stop(); }
From source file:org.apache.drill.exec.store.schedule.AffinityCreator.java
public static <T extends CompleteWork> List<EndpointAffinity> getAffinityMap(List<T> work) { Stopwatch watch = new Stopwatch(); long totalBytes = 0; for (CompleteWork entry : work) { totalBytes += entry.getTotalBytes(); }/*from w w w . j ava 2 s. c o m*/ ObjectFloatOpenHashMap<DrillbitEndpoint> affinities = new ObjectFloatOpenHashMap<DrillbitEndpoint>(); for (CompleteWork entry : work) { for (ObjectLongCursor<DrillbitEndpoint> cursor : entry.getByteMap()) { long bytes = cursor.value; float affinity = (float) bytes / (float) totalBytes; logger.debug("Work: {} Endpoint: {} Bytes: {}", work, cursor.key.getAddress(), bytes); affinities.putOrAdd(cursor.key, affinity, affinity); } } List<EndpointAffinity> affinityList = Lists.newLinkedList(); for (ObjectFloatCursor<DrillbitEndpoint> d : affinities) { logger.debug("Endpoint {} has affinity {}", d.key.getAddress(), d.value); affinityList.add(new EndpointAffinity(d.key, d.value)); } logger.debug("Took {} ms to get operator affinity", watch.elapsed(TimeUnit.MILLISECONDS)); return affinityList; }
From source file:com.google.devtools.build.android.LoggingProfiler.java
@Override public Profiler recordEndOf(String taskName) { Preconditions.checkArgument(tasks.containsKey(taskName)); final Stopwatch task = tasks.remove(taskName); logger.finer(String.format("%s in %ss", taskName, task.elapsed(TimeUnit.MILLISECONDS) / 1000f)); return this; }
From source file:org.opendaylight.infrautils.caches.sample.cli.SampleCacheCommand.java
@Override @Nullable/* ww w .java 2 s . com*/ @SuppressWarnings("checkstyle:RegexpSinglelineJava") public Object execute() { Stopwatch stopWatch = Stopwatch.createStarted(); String hello = sampleService.sayHello(whoToGreet); long ms = stopWatch.elapsed(TimeUnit.MILLISECONDS); System.out.println(ms + "ms: " + hello); return null; }
From source file:fr.ymanvieu.trading.Update.java
@Bean public ApplicationRunner run() { return (args) -> { List<SymbolEntity> symbols = symbolRepo.findAll(); SymbolEntity euro = symbolRepo.findOne("EUR"); ThreadLocalRandom r = ThreadLocalRandom.current(); IntStream.range(1, 11).forEach(ii -> { List<Quote> rates = new ArrayList<>(); int nb = ii * 1000; IntStream.range(0, nb).forEach(i -> { float fl = r.nextFloat() * symbols.size(); Calendar c = Calendar.getInstance(); c.setTime(new Date(r.nextLong(-30610227600000L, 253402210800000L))); rates.add(new Quote(euro.getCode(), symbols.get((int) fl).getCode(), new BigDecimal(fl), c.getTime()));//from w ww .j a v a 2s.co m }); Stopwatch sw = Stopwatch.createStarted(); hRateRepo.updateRates(rates); float rps = nb / (sw.elapsed(TimeUnit.MILLISECONDS) / 1000f); log.info("save {} rates in {} ({}/s)", nb, sw, rps); }); }; }
From source file:org.immutables.bench.Gatherer.java
void requestProcessed(Stopwatch stopwatch, int responseArity) { processedRequestCount.incrementAndGet(); stats.offer(new ResponseStatistic(stopwatch.elapsed(TimeUnit.MICROSECONDS), responseArity)); }
From source file:processing.FolkRankCalculator.java
private static void startFolkRankCreation(BookmarkReader reader, int sampleSize) { timeString = ""; System.out.println("\nStart FolkRank Calculation for Tags"); frResults = new ArrayList<int[]>(); prResults = new ArrayList<int[]>(); int size = reader.getUserLines().size(); int trainSize = size - sampleSize; Stopwatch timer = new Stopwatch(); timer.start();/*from ww w . j av a 2 s .c o m*/ FactReader factReader = new WikipediaFactReader(reader, trainSize, 3); FactPreprocessor prep = new FactReaderFactPreprocessor(factReader); prep.process(); FolkRankData facts = prep.getFolkRankData(); FolkRankParam param = new FolkRankParam(); FolkRankPref pref = new FolkRankPref(new double[] { 1.0, 1.0, 1.0 }); int usrCounts = facts.getCounts()[1].length; System.out.println("Users: " + usrCounts); int resCounts = facts.getCounts()[2].length; System.out.println("Resources: " + resCounts); double[][] prefWeights = new double[][] { new double[] {}, new double[] { usrCounts }, new double[] { resCounts } }; FolkRankAlgorithm folk = new FolkRankAlgorithm(param); timer.stop(); long trainingTime = timer.elapsed(TimeUnit.MILLISECONDS); timer = new Stopwatch(); // start FolkRank for (int i = trainSize; i < size; i++) { timer.start(); UserData data = reader.getUserLines().get(i); int u = data.getUserID(); int[] uPrefs = (u < usrCounts ? new int[] { u } : new int[] {}); int r = data.getWikiID(); int[] rPrefs = (r < resCounts ? new int[] { r } : new int[] {}); pref.setPreference(new int[][] { new int[] {}, uPrefs, rPrefs }, prefWeights); FolkRankResult result = folk.computeFolkRank(facts, pref); int[] topTags = new int[10]; SortedSet<ItemWithWeight> topKTags = ItemWithWeight.getTopK(facts, result.getWeights(), 10, 0); int count = 0; for (ItemWithWeight item : topKTags) { topTags[count++] = item.getItem(); } frResults.add(topTags); timer.stop(); int[] topTagsPr = new int[10]; SortedSet<ItemWithWeight> topKTagsPr = ItemWithWeight.getTopK(facts, result.getAPRWeights(), 10, 0); count = 0; for (ItemWithWeight item : topKTagsPr) { topTagsPr[count++] = item.getItem(); } prResults.add(topTagsPr); //System.out.println(u + "|" + data.getTags().toString().replace("[", "").replace("]", "") + // "|" + Arrays.toString(topTags).replace("[", "").replace("]", "") + // "|" + Arrays.toString(topTagsPr).replace("[", "").replace("]", "")); } 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"); }
From source file:org.obm.breakdownduration.BreakdownDurationFilter.java
private void endRecordingRequest(Stopwatch stopwatch) { try {//from ww w . ja v a 2s . co m breakdownDurationLoggerService.endRecordingNode(stopwatch.elapsed(TimeUnit.MILLISECONDS)); breakdownDurationLoggerService.disableRecording(); breakdownDurationLoggerService.log(); } finally { breakdownDurationLoggerService.cleanSession(); } }
From source file:io.v.android.apps.account_manager.AcceptBluetoothConnection.java
@Override protected BluetoothSocket doInBackground(Void... args) { if (mError != null) { return null; }//from ww w.j a va 2 s. co m if (mBluetoothAdapter.isDiscovering()) { mBluetoothAdapter.cancelDiscovery(); } BluetoothSocket socket = null; Stopwatch stopwatch = Stopwatch.createUnstarted(); for (stopwatch.start(); stopwatch.elapsed(TimeUnit.SECONDS) <= TRY_FOR; socket = null) { try { socket = mRemoteDevice.createRfcommSocketToServiceRecord(mUuid); if (socket != null && socket.getRemoteDevice().equals(mRemoteDevice)) { socket.connect(); return socket; } } catch (IOException e) { // Do nothing. } } try { socket = mRemoteDevice.createRfcommSocketToServiceRecord(mUuid); socket.connect(); return socket; } catch (IOException e) { mError = e.getMessage(); try { socket.close(); return null; } catch (IOException eClose) { mError += "\n" + eClose.getMessage(); return null; } } }