Java Code Examples for com.google.common.base.Stopwatch#createUnstarted()
The following examples show how to use
com.google.common.base.Stopwatch#createUnstarted() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ASMReflectorTest.java From meghanada-server with GNU General Public License v3.0 | 6 votes |
@Test public void testReflectAll5() throws Exception { ASMReflector asmReflector = ASMReflector.getInstance(); Stopwatch stopwatch = Stopwatch.createUnstarted(); // Config.load().setDebug(); { File jar = getRTJar(); // Config.load().setDebug(); String fqcn = "java.util.stream.Stream<java.util.stream.Stream<java.util.List<java.lang.String>>>"; Map<String, ClassIndex> index = asmReflector.getClassIndexes(jar); final InheritanceInfo info = asmReflector.getReflectInfo(index, fqcn); System.out.println(info); stopwatch.start(); List<MemberDescriptor> memberDescriptors1 = asmReflector.reflectAll(info); System.out.println(stopwatch.stop()); System.out.println(memberDescriptors1.size()); memberDescriptors1.forEach( md -> { // System.out.println(md.getDeclaration()); // System.out.println(md.declaration); }); } }
Example 2
Source File: ASMReflectorTest.java From meghanada-server with GNU General Public License v3.0 | 6 votes |
@Test public void testReflectAll1() throws Exception { ASMReflector asmReflector = ASMReflector.getInstance(); Stopwatch stopwatch = Stopwatch.createUnstarted(); { File jar = getRTJar(); String fqcn = "java.util.stream.Stream<java.util.List<java.lang.String>>"; Map<String, ClassIndex> index = asmReflector.getClassIndexes(jar); final InheritanceInfo info = asmReflector.getReflectInfo(index, fqcn); stopwatch.start(); List<MemberDescriptor> memberDescriptors1 = asmReflector.reflectAll(info); System.out.println(stopwatch.stop()); System.out.println(memberDescriptors1.size()); memberDescriptors1.forEach( md -> { System.out.println(md.getDeclaration()); }); stopwatch.reset(); stopwatch.start(); List<MemberDescriptor> memberDescriptors2 = asmReflector.reflectAll(info); System.out.println(stopwatch.stop()); System.out.println(memberDescriptors2.size()); } }
Example 3
Source File: ASMReflectorTest.java From meghanada-server with GNU General Public License v3.0 | 6 votes |
@Test public void testReflectAll4() throws Exception { ASMReflector asmReflector = ASMReflector.getInstance(); Stopwatch stopwatch = Stopwatch.createUnstarted(); { File jar = getRTJar(); String fqcn = "java.util.function.Predicate"; Map<String, ClassIndex> index = asmReflector.getClassIndexes(jar); final InheritanceInfo info = asmReflector.getReflectInfo(index, fqcn); System.out.println(info); stopwatch.start(); List<MemberDescriptor> memberDescriptors = asmReflector.reflectAll(info); System.out.println(stopwatch.stop()); assertEquals(16, memberDescriptors.size()); memberDescriptors.forEach( memberDescriptor -> System.out.println(memberDescriptor.getDeclaration())); } }
Example 4
Source File: HealthCheckedEndpointGroupLongPollingTest.java From armeria with Apache License 2.0 | 6 votes |
@Test void periodicCheckWhenConnectionRefused() throws Exception { final BlockingQueue<RequestLog> healthCheckRequestLogs = new LinkedTransferQueue<>(); this.healthCheckRequestLogs = healthCheckRequestLogs; final Endpoint endpoint = Endpoint.of("127.0.0.1", 1); try (HealthCheckedEndpointGroup endpointGroup = build( HealthCheckedEndpointGroup.builder(endpoint, HEALTH_CHECK_PATH))) { // Check the initial state (unhealthy). assertThat(endpointGroup.endpoints()).isEmpty(); // Drop the first request. healthCheckRequestLogs.take(); final Stopwatch stopwatch = Stopwatch.createUnstarted(); for (int i = 0; i < 2; i++) { stopwatch.reset().start(); healthCheckRequestLogs.take(); assertThat(stopwatch.elapsed(TimeUnit.MILLISECONDS)) .isGreaterThan(RETRY_INTERVAL.toMillis() * 4 / 5); } } finally { this.healthCheckRequestLogs = null; } }
Example 5
Source File: ASMReflectorTest.java From meghanada-server with GNU General Public License v3.0 | 6 votes |
@Test public void testGetReflectClass2() throws Exception { ASMReflector asmReflector = ASMReflector.getInstance(); Stopwatch stopwatch = Stopwatch.createUnstarted(); { String fqcn = "java.util.stream.Stream"; File jar = getRTJar(); Map<String, ClassIndex> index = asmReflector.getClassIndexes(jar); stopwatch.start(); final InheritanceInfo info1 = asmReflector.getReflectInfo(index, fqcn); System.out.println(stopwatch.stop()); System.out.println(info1); stopwatch.reset(); stopwatch.start(); final InheritanceInfo info2 = asmReflector.getReflectInfo(index, fqcn); System.out.println(stopwatch.stop()); System.out.println(info2); } }
Example 6
Source File: LinkedSparseMatrixTest.java From matrix-toolkits-java with GNU Lesser General Public License v3.0 | 6 votes |
public void ignoredTimedTransMult() { Stopwatch watch = Stopwatch.createUnstarted(); DenseMatrix dense = new DenseMatrix(1000, 1000); int[][] nz = Utilities.getRowPattern(dense.numRows(), dense.numColumns(), 100); Utilities.rowPopulate(dense, nz); log.info("created matrices"); Matrix sparse = new LinkedSparseMatrix(dense.numRows(), dense.numColumns()); sparse.set(dense); for (Matrix m : Lists.newArrayList(dense, sparse)) { log.info("starting " + m.getClass()); Matrix t = new DenseMatrix(m); Matrix o = new DenseMatrix(dense.numRows(), dense.numColumns()); log.info("warming up " + m.getClass() + " " + o.getClass()); for (int i = 0; i < 10; i++) m.transAmult(t, o); log.info("starting " + m.getClass() + " " + o.getClass()); watch.start(); for (int i = 0; i < 100; i++) m.transAmult(t, o); watch.stop(); log.info(m.getClass() + " " + o.getClass() + " " + watch); } }
Example 7
Source File: ASMReflectorTest.java From meghanada-server with GNU General Public License v3.0 | 6 votes |
@Test public void testReflectInner2() throws Exception { ASMReflector asmReflector = ASMReflector.getInstance(); Stopwatch stopwatch = Stopwatch.createUnstarted(); { String fqcn = "java.util.Map.Entry"; File jar = getRTJar(); Map<String, ClassIndex> index = asmReflector.getClassIndexes(jar); final InheritanceInfo info = asmReflector.getReflectInfo(index, fqcn); System.out.println(info); stopwatch.start(); List<MemberDescriptor> memberDescriptors = asmReflector.reflectAll(info); System.out.println(stopwatch.stop()); memberDescriptors.forEach(m -> System.out.println(m.getDisplayDeclaration())); assertEquals(18, memberDescriptors.size()); stopwatch.reset(); } }
Example 8
Source File: Java8Test.java From Copiers with Apache License 2.0 | 6 votes |
@Test public void list() { Copier<SimpleSource, SimpleTarget> copier = Copiers.create(SimpleSource.class, SimpleTarget.class); int size = 500000; List<SimpleSource> sourceList = IntStream.range(0, size).mapToObj(SimpleSource::new).collect(toList()); Stopwatch stopwatch = Stopwatch.createUnstarted(); stopwatch.start(); List<SimpleTarget> targetList1 = copier.copyList(sourceList); log.info("单线程耗时: {}ms, 大小: {}", stopwatch.elapsed(TimeUnit.MILLISECONDS), targetList1.size()); List<SimpleTarget> targetList2 = new ArrayList<>(sourceList.size()); stopwatch.reset().start(); sourceList.stream().parallel().map(copier::copy).forEach(targetList2::add); log.info("多线程耗时: {}ms, 大小: {}", stopwatch.elapsed(TimeUnit.MILLISECONDS), targetList2.size()); List<SimpleTarget> targetList3 = new ArrayList<>(sourceList.size()); stopwatch.reset().start(); sourceList.stream().parallel().map(copier::copy).forEachOrdered(targetList3::add); log.info("多线程 Ordered 耗时: {}ms, 大小: {}", stopwatch.elapsed(TimeUnit.MILLISECONDS), targetList3.size()); }
Example 9
Source File: NettyClientHandlerTest.java From grpc-nebula-java with Apache License 2.0 | 5 votes |
@Override protected NettyClientHandler newHandler() throws Http2Exception { Http2Connection connection = new DefaultHttp2Connection(false); // Create and close a stream previous to the nextStreamId. Http2Stream stream = connection.local().createStream(streamId - 2, true); stream.close(); final Ticker ticker = new Ticker() { @Override public long read() { return nanoTime; } }; Supplier<Stopwatch> stopwatchSupplier = new Supplier<Stopwatch>() { @Override public Stopwatch get() { return Stopwatch.createUnstarted(ticker); } }; return NettyClientHandler.newHandler( connection, frameReader(), frameWriter(), lifecycleManager, mockKeepAliveManager, flowControlWindow, maxHeaderListSize, stopwatchSupplier, tooManyPingsRunnable, transportTracer, Attributes.EMPTY, "someauthority"); }
Example 10
Source File: OkHttpClientTransportTest.java From grpc-java with Apache License 2.0 | 5 votes |
private void startTransport(int startId, @Nullable Runnable connectingCallback, boolean waitingForConnected, int maxMessageSize, int initialWindowSize, String userAgent) throws Exception { connectedFuture = SettableFuture.create(); final Ticker ticker = new Ticker() { @Override public long read() { return nanoTime; } }; Supplier<Stopwatch> stopwatchSupplier = new Supplier<Stopwatch>() { @Override public Stopwatch get() { return Stopwatch.createUnstarted(ticker); } }; clientTransport = new OkHttpClientTransport( userAgent, executor, frameReader, frameWriter, new OkHttpFrameLogger(Level.FINE, logger), startId, socket, stopwatchSupplier, connectingCallback, connectedFuture, maxMessageSize, initialWindowSize, tooManyPingsRunnable, new TransportTracer()); clientTransport.start(transportListener); if (waitingForConnected) { connectedFuture.get(TIME_OUT_MS, TimeUnit.MILLISECONDS); } }
Example 11
Source File: PinotDataAndQueryAnonymizer.java From incubator-pinot with Apache License 2.0 | 5 votes |
/** * Write global dictionaries and column name mapping to disk * @throws Exception */ private void writeGlobalDictionariesAndColumnMapping() throws Exception { // write column name mapping Stopwatch stopwatch = Stopwatch.createUnstarted(); stopwatch.start(); writeColumnMapping(); _globalDictionaries.serialize(_outputDir); stopwatch.stop(); LOGGER.info("Finished writing global dictionaries and column name mapping to disk. Time taken: {}secs. Please see the files in {}", stopwatch.elapsed(TimeUnit.SECONDS), _outputDir); }
Example 12
Source File: AsyncTaskWrapper.java From dremio-oss with Apache License 2.0 | 5 votes |
public AsyncTaskWrapper(SchedulingGroup<AsyncTaskWrapper> schedulingGroup, AsyncTask asyncTask, AutoCloseable cleaner, int warnMaxTime) { super(); this.schedulingGroup = Preconditions.checkNotNull(schedulingGroup, "Scheduling group required"); this.asyncTask = Preconditions.checkNotNull(asyncTask); asyncTask.setTaskDescriptor(taskDescriptor); this.cleaner = Preconditions.checkNotNull(cleaner); this.warnMaxTime = warnMaxTime; for (int i = 0; i < WatchType.Size; i++) { watches[i] = Stopwatch.createUnstarted(); } stateStarted(); }
Example 13
Source File: NettyClientHandlerTest.java From grpc-java with Apache License 2.0 | 5 votes |
@Override protected NettyClientHandler newHandler() throws Http2Exception { Http2Connection connection = new DefaultHttp2Connection(false); // Create and close a stream previous to the nextStreamId. Http2Stream stream = connection.local().createStream(streamId - 2, true); stream.close(); final Ticker ticker = new Ticker() { @Override public long read() { return nanoTime; } }; Supplier<Stopwatch> stopwatchSupplier = new Supplier<Stopwatch>() { @Override public Stopwatch get() { return Stopwatch.createUnstarted(ticker); } }; return NettyClientHandler.newHandler( connection, frameReader(), frameWriter(), lifecycleManager, mockKeepAliveManager, false, flowControlWindow, maxHeaderListSize, stopwatchSupplier, tooManyPingsRunnable, transportTracer, Attributes.EMPTY, "someauthority"); }
Example 14
Source File: DurationPredicatesTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
private static Stopwatch createStopwatchWithElapsedTime(Duration duration) throws Exception { if (duration == null) { return null; } Stopwatch stopwatch = Stopwatch.createUnstarted(); Field field = stopwatch.getClass().getDeclaredField("elapsedNanos"); field.setAccessible(true); field.set(stopwatch, duration.nanos()); return stopwatch; }
Example 15
Source File: ASMReflectorTest.java From meghanada-server with GNU General Public License v3.0 | 5 votes |
@Test public void testReflectAnnotation1() throws Exception { ASMReflector asmReflector = ASMReflector.getInstance(); Stopwatch stopwatch = Stopwatch.createUnstarted(); { String fqcn = "org.junit.Test"; File jar = getJar("junit:junit"); stopwatch.start(); List<MemberDescriptor> memberDescriptors = timeIt( () -> { Map<String, ClassIndex> index = asmReflector.getClassIndexes(jar); // Map<ClassIndex, File> index = asmReflector.getClasses(jar); // index // .keySet() // .forEach( // classIndex -> { // if (classIndex.isAnnotation) { // System.out.println("anno: " + classIndex); // } // }); final InheritanceInfo info = asmReflector.getReflectInfo(index, fqcn); return asmReflector.reflectAll(info); }); System.out.println(stopwatch.stop()); memberDescriptors.forEach( m -> { System.out.println(m.getDeclaration()); }); assertEquals(2, memberDescriptors.size()); stopwatch.reset(); } }
Example 16
Source File: MLTimer.java From RecSys2018 with Apache License 2.0 | 4 votes |
public MLTimer(final String nameP) { this.name = nameP; this.loopSize = 0; this.timer = Stopwatch.createUnstarted(); }
Example 17
Source File: StatsManager.java From connector-sdk with Apache License 2.0 | 4 votes |
private SimpleEvent(String op) { this.op = op; this.watch = Stopwatch.createUnstarted(); }
Example 18
Source File: BGPSessionStateImpl.java From bgpcep with Eclipse Public License 1.0 | 4 votes |
public BGPSessionStateImpl() { this.sessionState = State.OPEN_CONFIRM; this.sessionStopwatch = Stopwatch.createUnstarted(); }
Example 19
Source File: ScheduledExecutionTest.java From brooklyn-server with Apache License 2.0 | 4 votes |
@Test(groups="Integration") public void testScheduledTaskCancelOuter() throws Exception { final Duration PERIOD = Duration.millis(20); final Duration CYCLE_DELAY = Duration.ONE_SECOND; // this should be enough to start the next cycle, but not so much that the cycle ends; // and enough that when a task is interrupted it terminates within this period final Duration SMALL_FRACTION_OF_CYCLE_DELAY = PERIOD.add(CYCLE_DELAY.multiply(0.1)); BasicExecutionManager m = new BasicExecutionManager("mycontextid"); final AtomicInteger i = new AtomicInteger(); ScheduledTask t = new ScheduledTask(MutableMap.of("delay", PERIOD.times(2), "period", PERIOD), new Callable<Task<?>>() { @Override public Task<?> call() throws Exception { return new BasicTask<Integer>(new Callable<Integer>() { @Override public Integer call() { log.info("task running ("+i+"): "+Tasks.current()+" "+Tasks.current().getStatusDetail(false)); Time.sleep(CYCLE_DELAY); i.incrementAndGet(); return i.get(); }}); }}); log.info(JavaClassNames.niceClassAndMethod()+" - submitting {} {}", t, t.getStatusDetail(false)); m.submit(t); log.info("submitted {} {}", t, t.getStatusDetail(false)); Integer interimResult = (Integer) t.get(); log.info("done one ({}) {} {}", new Object[] {interimResult, t, t.getStatusDetail(false)}); assertEquals(i.get(), 1); Time.sleep(SMALL_FRACTION_OF_CYCLE_DELAY); assertEquals(t.get(), 2); Time.sleep(SMALL_FRACTION_OF_CYCLE_DELAY); Stopwatch timer = Stopwatch.createUnstarted(); t.cancel(true); t.blockUntilEnded(); // int finalResult = t.get() log.info("blocked until ended ({}) {} {}, in {}", new Object[] {i, t, t.getStatusDetail(false), Duration.of(timer)}); try { t.get(); Assert.fail("Should have failed getting result of cancelled "+t); } catch (Exception e) { /* expected */ } assertEquals(i.get(), 2); log.info("ended ({}) {} {}, in {}", new Object[] {i, t, t.getStatusDetail(false), Duration.of(timer)}); Assert.assertTrue(Duration.of(timer).isShorterThan(SMALL_FRACTION_OF_CYCLE_DELAY)); }
Example 20
Source File: FakeClock.java From grpc-java with Apache License 2.0 | 4 votes |
@Override public Stopwatch get() { return Stopwatch.createUnstarted(ticker); }