Guava Stopwatch - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Guava Stopwatch class.

This code example shows how to use the following methods:start, stop, toString, elapsedTime
    public void shouldPrintIterationsTime() throws Exception {
 
        // given 
        Ticker ticker = mock(Ticker.class);
        when(ticker.read()).thenReturn(0L, 2*60*60*1000000000L); // 2 hours
        Stopwatch stopwatch = new Stopwatch(ticker);
 
        // when 
        stopwatch.start();
        // some method is called here 
        stopwatch.stop();
 
        // then 
        assertThat(stopwatch.toString()).isEqualTo("7200 s");
        assertThat(stopwatch.elapsedTime(TimeUnit.MINUTES)).isEqualTo(120);
        assertThat(stopwatch.elapsedTime(TimeUnit.HOURS)).isEqualTo(2);
    } 
 
} 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:elapsed, start
    doSetup(context, hyperBatch, null);
  } 
 
  @Override 
  public void sort(SelectionVector4 vector4, VectorContainer container){
    Stopwatch watch = new Stopwatch();
    watch.start();
    QuickSort qs = new QuickSort();
    qs.sort(this, 0, vector4.getTotalCount());
    logger.debug("Took {} us to sort {} records", watch.elapsed(TimeUnit.MICROSECONDS), vector4.getTotalCount());
  } 
 
  @Override 
  public void swap(int sv0, int sv1) {
    int tmp = vector4.get(sv0);
    vector4.set(sv0, vector4.get(sv1));
    vector4.set(sv1, tmp);
  } 
 
  @Override 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:elapsed, start
  } 
 
  @Override 
  public void sort(SelectionVector2 vector2){
    QuickSort qs = new QuickSort();
    Stopwatch watch = new Stopwatch();
    watch.start();
    if (vector2.getCount() > 0) {
      qs.sort(this, 0, vector2.getCount());
    } 
    logger.debug("Took {} us to sort {} records", watch.elapsed(TimeUnit.MICROSECONDS), vector2.getCount());
  } 
 
  @Override 
  public void swap(int sv0, int sv1) {
    char tmp = vector2.getIndex(sv0);
    vector2.setIndex(sv0, vector2.getIndex(sv1));
    vector2.setIndex(sv1, tmp);
  } 
 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:isRunning, reset, start
        return (stopwatch.isRunning()) && (elapsed <= followerTimeoutMillis);
    } 
 
    @Override 
    public void markFollowerActive() { 
        if (stopwatch.isRunning()) {
            stopwatch.reset();
        } 
        stopwatch.start();
    } 
 
    @Override 
    public void markFollowerInActive() { 
        if (stopwatch.isRunning()) {
            stopwatch.stop();
        } 
    } 
} 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
 
   private Stopwatch stopwatch;
 
   @BeforeMethod 
   public void setUp() { 
      stopwatch = new Stopwatch();
   } 
    
   @Test
   void testFalseOnIllegalStateExeception() { 
      ensureImmediateReturnFor(new IllegalStateException());
   } 
 
   @SuppressWarnings("serial") 
   @Test
   void testFalseOnExecutionException() { 
      ensureImmediateReturnFor(new ExecutionException() {
      }); 
   } 
 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:isRunning, stop
		} 
		return deltaTimeMs;
	} 
 
	public void stop() { 
		if (stopWatch.isRunning())
			stopWatch.stop().reset();
	} 
 
	public void reset() { 
		stop(); 
	} 
} 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
     
    public static void main(String[] args) throws  Exception {
        Injector injector = Guice.createInjector(new AsynchronousServerModule());
        AsyncSocketServerGuiceExample socketServer = injector.getInstance(AsyncSocketServerGuiceExample.class);
        System.out.println("Starting the EchoSever");
        Stopwatch stopwatch = new Stopwatch().start();
        socketServer.runServer();
        stopwatch.stop();
        System.out.println("EchoServer is done in "+stopwatch.elapsedMillis());
    } 
} 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
 
  @Test
  public void testLoad() throws Exception {
    ClientRecommender client = getClient();
    LoadRunner runner = new LoadRunner(client, getTestTempDir(), 5000);
    Stopwatch stopwatch = new Stopwatch().start();
    runner.runLoad();
    assertTrue(stopwatch.elapsed(TimeUnit.MILLISECONDS) < 40 * runner.getSteps());
  } 
 
} 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
    public void waitForProcessEnd(String processInstanceId) throws Exception {
        waitForProcessEnd(processInstanceId, 60000 /* milliseconds */);
    } 
 
    public void waitForProcessEnd(final String processInstanceId, int timeoutInMilliseconds) throws Exception {
        Stopwatch stopwatch = new Stopwatch().start();
        while (isProcessNotEnded(processInstanceId)) {
            if (stopwatch.elapsedMillis() > timeoutInMilliseconds) {
                throw new TimeoutException(String.format("Process %s not ended in %d milliseconds.",
                    processInstanceId, timeoutInMilliseconds));
            } 
            LOG.info(String.format("Process instance %s not ended. Waiting 1s.", processInstanceId));
            TimeUnit.SECONDS.sleep(1);
        } 
        LOG.info(String.format("Process instance %s ended as expected in less than %d milliseconds",
            processInstanceId, timeoutInMilliseconds));
    } 
 
    private boolean isProcessNotEnded(final String processInstanceId) throws InterruptedException {
        ProcessInstance localInstance = getProcessInstanceById(processInstanceId);
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
		return new org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder(rounds);
	} 
 
	@Override 
	public String encode(CharSequence rawPassword) {
		Stopwatch stopwatch = new Stopwatch().start();
		String encPass = encoder.encode(rawPassword);
		if (log.isTraceEnabled()) { 
			log.trace("time taken to encode password: {} ms", stopwatch.stop().elapsed(TimeUnit.MILLISECONDS)); //$NON-NLS-1$
		} 
		return encPass;
	} 
 
	@Override 
	public boolean matches(CharSequence rawPassword, String encodedPassword) {
		Stopwatch stopwatch = new Stopwatch().start();
		boolean valid = encoder.matches(rawPassword, encodedPassword);
		if (log.isTraceEnabled()) { 
			log.trace("time taken to verify password: {} ms", stopwatch.stop().elapsed(TimeUnit.MILLISECONDS)); //$NON-NLS-1$
		} 
5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
See Code Examples for Guava Stopwatch Methods: