/** * <p> * Gets a summary of the time that the stopwatch recorded as a string. * </p> * * <p> * The format used is ISO 8601-like, <i>hours</i>:<i>minutes</i>:<i>seconds</i>.<i>milliseconds</i>. * </p> * * @return the time as a String */ @Override public String toString() { return DurationFormatUtils.formatDurationHMS(getTime()); }
@Test public void testStopWatchGetWithTimeUnit() { // Create a mock StopWatch with a time of 2:59:01.999 final StopWatch watch = createMockStopWatch( TimeUnit.HOURS.toNanos(2) + TimeUnit.MINUTES.toNanos(59) + TimeUnit.SECONDS.toNanos(1) + TimeUnit.MILLISECONDS.toNanos(999)); assertEquals(2L, watch.getTime(TimeUnit.HOURS)); assertEquals(179L, watch.getTime(TimeUnit.MINUTES)); assertEquals(10741L, watch.getTime(TimeUnit.SECONDS)); assertEquals(10741999L, watch.getTime(TimeUnit.MILLISECONDS)); }
@Override public Void call() throws Exception { ZooKeeper zooKeeper = null; try { zooKeeper = new ZooKeeper(host, timeout, EmptyWatcher.instance); Stat exists = zooKeeper.exists(znode, false); StopWatch stopwatch = new StopWatch(); stopwatch.start(); zooKeeper.getData(znode, false, exists); stopwatch.stop(); sink.publishReadTiming(znode, host, stopwatch.getTime()); } catch (KeeperException | InterruptedException e) { sink.publishReadFailure(znode, host); } finally { if (zooKeeper != null) { zooKeeper.close(); } } return null; } }
@Test public void testLang315() { final StopWatch watch = new StopWatch(); watch.start(); try { Thread.sleep(200); } catch (final InterruptedException ex) { } watch.suspend(); final long suspendTime = watch.getTime(); try { Thread.sleep(200); } catch (final InterruptedException ex) { } watch.stop(); final long totalTime = watch.getTime(); assertTrue(suspendTime == totalTime); }
@Test public void testStopWatchSimple() { final StopWatch watch = new StopWatch(); watch.start(); try { Thread.sleep(550); } catch (final InterruptedException ex) { } watch.stop(); final long time = watch.getTime(); assertEquals(time, watch.getTime()); assertTrue(time >= 500); assertTrue(time < 700); watch.reset(); assertEquals(0, watch.getTime()); }
@Test public void testStopWatchSuspend() { final StopWatch watch = new StopWatch(); watch.start(); try { Thread.sleep(550); } catch (final InterruptedException ex) { } watch.suspend(); final long suspendTime = watch.getTime(); try { Thread.sleep(550); } catch (final InterruptedException ex) { } watch.resume(); try { Thread.sleep(550); } catch (final InterruptedException ex) { } watch.stop(); final long totalTime = watch.getTime(); assertTrue(suspendTime >= 500); assertTrue(suspendTime < 700); assertTrue(totalTime >= 1000); assertTrue(totalTime < 1300); }
private static void timerTests(final CellBlockBuilder builder, final int count, final int size, final Codec codec, final CompressionCodec compressor) throws IOException { final int cycles = 1000; StopWatch timer = new StopWatch(); timer.start(); for (int i = 0; i < cycles; i++) { timerTest(builder, timer, count, size, codec, compressor, false); } timer.stop(); LOG.info("Codec=" + codec + ", compression=" + compressor + ", sized=" + false + ", count=" + count + ", size=" + size + ", + took=" + timer.getTime() + "ms"); timer.reset(); timer.start(); for (int i = 0; i < cycles; i++) { timerTest(builder, timer, count, size, codec, compressor, true); } timer.stop(); LOG.info("Codec=" + codec + ", compression=" + compressor + ", sized=" + true + ", count=" + count + ", size=" + size + ", + took=" + timer.getTime() + "ms"); }
private CandidateResults testQuery( final SearchEdge scope, final SearchTypes searchTypes, final String queryString, final int num ) { StopWatch timer = new StopWatch(); timer.start(); CandidateResults candidateResults = entityIndex.search( scope, searchTypes, queryString, 1000, 0, false ); timer.stop(); assertEquals(num, candidateResults.size()); logger.debug("Query time {}ms", timer.getTime()); return candidateResults; }
sink.publishReadTiming(tableName.getNameAsString(), serverName, stopWatch.getTime()); } catch (TableNotFoundException tnfe) { LOG.error("Table may be deleted", tnfe);
@Test public void testStopWatchSplit() { final StopWatch watch = new StopWatch(); watch.start(); try { Thread.sleep(550); } catch (final InterruptedException ex) { } watch.split(); final long splitTime = watch.getSplitTime(); final String splitStr = watch.toSplitString(); try { Thread.sleep(550); } catch (final InterruptedException ex) { } watch.unsplit(); try { Thread.sleep(550); } catch (final InterruptedException ex) { } watch.stop(); final long totalTime = watch.getTime(); assertEquals("Formatted split string not the correct length", splitStr.length(), 12); assertTrue(splitTime >= 500); assertTrue(splitTime < 700); assertTrue(totalTime >= 1500); assertTrue(totalTime < 1900); }
private void insertJsonBlob( List<Object> sampleJson, EntityIndexBatch batch, String entityType, IndexEdge indexEdge, final int max, final int startIndex ) throws IOException { int count = 0; StopWatch timer = new StopWatch(); timer.start(); if ( startIndex > 0 ) { for ( int i = 0; i < startIndex; i++ ) { sampleJson.remove( 0 ); } } for ( Object o : sampleJson ) { Map<String, Object> item = ( Map<String, Object> ) o; Entity entity = new Entity( entityType ); entity = EntityIndexMapUtils.fromMap( entity, item ); EntityUtils.setVersion( entity, UUIDGenerator.newTimeUUID() ); entity.setField( new UUIDField( IndexingUtils.ENTITY_ID_FIELDNAME, UUID.randomUUID() ) ); batch.index( indexEdge, entity ); if ( ++count > max ) { break; } } timer.stop(); logger.info( "Total time to index {} entries {}ms, average {}ms/entry", new Object[] { count, timer.getTime(), timer.getTime() / count } ); }
logger.debug("Query time {}ms", timer.getTime());
logger.debug( "Query time {}ms", timer.getTime() );