Code example for Stopwatch

Methods: startstop, elapsedMillis

0
    public void shouldCalculateIterationsTime() throws Exception {
 
        // given 
        Ticker ticker = mock(Ticker.class);
        when(ticker.read()).thenReturn(0L, 2000000000L);
        Stopwatch stopwatch = new Stopwatch(ticker);
 
        // when 
        stopwatch.start();
        // some method is called here 
        stopwatch.stop();
 
        // then 
        assertThat(stopwatch.elapsedMillis()).isEqualTo(2000L);
    } 
 
    @Test
    public void shouldPrintIterationsTime() throws Exception {
 
        // given 
Experience pair programming with AI  Get Codota for Java