Example usage for com.google.common.base Stopwatch createStarted

List of usage examples for com.google.common.base Stopwatch createStarted

Introduction

In this page you can find the example usage for com.google.common.base Stopwatch createStarted.

Prototype

@CheckReturnValue
public static Stopwatch createStarted() 

Source Link

Document

Creates (and starts) a new stopwatch using System#nanoTime as its time source.

Usage

From source file:it.itsoftware.chartx.kafka.tests.TickProducerMain.java

public static void main(String[] args) {

    String topic = "ticks";
    TickSource source = new SimulatedSmartTickSource(10, 100, 10);
    ((SimulatedSmartTickSource) source).randomize();
    KafkaTickProducer producer = new KafkaTickProducer(source, topic, KafkaTickProducer.defaultProperties());
    int nMessages = 25;
    boolean asyncSend = true;
    int executionTime = 15 * 60; // time in seconds for data production

    Stopwatch exitTimer = Stopwatch.createStarted();
    ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
    Runnable writeProcess = () -> {
        if (exitTimer.elapsed(TimeUnit.SECONDS) > executionTime) {
            logger.info("Timeout reached, shutting down producer");
            producer.close();//from w ww.j av a2s . com
            executor.shutdown();
            return;
        }
        logger.info("Producing " + nMessages + " messages.");
        Stopwatch timer = Stopwatch.createStarted();
        if (asyncSend) {
            producer.produceAsync(nMessages);
        } else {
            producer.produceSync(nMessages);
        }
        logger.info("Sent in " + (timer.elapsed(TimeUnit.MICROSECONDS) / 1000.0d) + "ms");
    };

    int initialDelay = 0;
    int period = 1000;
    executor.scheduleAtFixedRate(writeProcess, initialDelay, period, TimeUnit.MILLISECONDS);

}

From source file:org.glowroot.agent.fat.storage.TraceDaoPerformanceMain.java

public static void main(String... args) throws Exception {
    DataSource dataSource = new DataSource();
    CappedDatabase cappedDatabase = new CappedDatabase(new File("glowroot.capped.db"), 1000000,
            Ticker.systemTicker());//from   w  w w. j  ava 2  s.c om
    TraceDao traceDao = new TraceDao(dataSource, cappedDatabase, mock(TransactionTypeDao.class));

    Stopwatch stopwatch = Stopwatch.createStarted();
    for (int i = 0; i < 1000; i++) {
        Trace trace = TraceTestData.createTrace();
        traceDao.collect(SERVER_ID, trace);
    }
    logger.info("elapsed time: {}", stopwatch.elapsed(MILLISECONDS));
}

From source file:com.paolodragone.wsn.extraction.SenseExtractor.java

public static void main(String[] args) {
    Stopwatch stopwatch = Stopwatch.createStarted();
    try {/*from   w w  w .java  2s.  c  o m*/
        WsnConfiguration configuration = WsnConfiguration.getInstance();
        Path wiktionaryDumpFilePath = configuration.getWiktionaryDumpFilePath();
        Path sensesFilePath = configuration.getSensesFilePath();

        SenseExtractor extractor = new SenseExtractor();
        SenseCountPrinter senseCountPrinter = new SenseCountPrinter(extractor);
        Timer senseCountPrinterTimer = new Timer("SenseCountPrinter", true);
        senseCountPrinterTimer.scheduleAtFixedRate(senseCountPrinter, 0, 1000);

        Reader wiktionaryDumpFileReader = Files.newBufferedReader(wiktionaryDumpFilePath);
        Stream<Sense> senseStream = extractor.extractSenses(wiktionaryDumpFileReader);

        SensesDataSet sensesDataSet = new SensesDataSet();
        Writer sensesFileWriter = Files.newBufferedWriter(sensesFilePath);
        sensesDataSet.writeEntities(senseStream, sensesFileWriter);

    } catch (Exception e) {
        e.printStackTrace();
    }
    long elapsed = stopwatch.stop().elapsed(TimeUnit.MINUTES);
    System.out.println("\nTotal time: " + elapsed + " min");
}

From source file:com.jejking.hh.nord.gazetteer.osm.streets.WriteStreets.java

/**
 * Imports an extract from Open Street Map into Neo4j.
 * //w  ww.  j  a  v a 2 s.com
 * @param args
 *            directory in which the Neo4j database exists.
 */
public static void main(String[] args) {
    Stopwatch stopwatch = Stopwatch.createStarted();
    GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(null);
    GraphDatabaseService graph = new GraphDatabaseFactory().newEmbeddedDatabase(args[0]);
    registerShutdownHook(graph);

    WriteStreets.writeStreets(geometryFactory, graph);
    System.out.println("Wrote streets. Elapsed time: " + stopwatch.elapsed(TimeUnit.SECONDS) + " seconds");

}

From source file:nl.knaw.huygens.timbuctoo.tools.other.ReIndexer.java

public static void main(String[] args) throws Exception {
    Stopwatch stopwatch = Stopwatch.createStarted();

    Injector injector = ToolsInjectionModule.createInjector();
    Repository repository = injector.getInstance(Repository.class);
    IndexManager indexManager = injector.getInstance(IndexManager.class);

    try {/*www .j  a  va 2s  . c o  m*/
        new ReIndexer().indexAsynchronous(repository, indexManager);
    } finally {
        repository.close();
        indexManager.close();
        LOG.info("Time used: {}", stopwatch);
    }
}

From source file:com.jejking.hh.nord.app.CreateGazetteer.java

/**
 * @param args//  w w w  .ja  v a 2s . c o  m
 */
public static void main(String[] args) {
    Stopwatch stopwatch = Stopwatch.createStarted();
    GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(null);
    GraphDatabaseService graph = new GraphDatabaseFactory().newEmbeddedDatabase(args[0]);
    registerShutdownHook(graph);

    // we want an additional index on adminstrative area - name
    setupSchema(graph);
    System.out.println("Setup indexes. Elapsed time: " + stopwatch.elapsed(TimeUnit.SECONDS) + " seconds");

    CreatePartialGazetteerWithOpenData.writeHamburgPolygons(graph);
    System.out.println(
            "Wrote hamburg polygons. Elapsed time: " + stopwatch.elapsed(TimeUnit.SECONDS) + " seconds");

    WriteStreets.writeStreets(geometryFactory, graph);
    System.out.println("Wrote streets. Elapsed time: " + stopwatch.elapsed(TimeUnit.SECONDS) + " seconds");

    MapStreetsToPolygons.mapStreetsToAdminPolygons(graph);
    System.out.println(
            "Linked streets to polygons. Elapsed time: " + stopwatch.elapsed(TimeUnit.SECONDS) + " seconds");

    WritePointsOfInterest.writePointsOfInterest(geometryFactory, graph);
    System.out.println(
            "Wrote points of interest. Elapsed time: " + stopwatch.elapsed(TimeUnit.SECONDS) + " seconds");

    graph.shutdown();
    System.out.println("Done. Elapsed time: " + stopwatch.elapsed(TimeUnit.SECONDS) + " seconds");
}

From source file:org.glowroot.agent.embedded.repo.TraceDaoPerformanceMain.java

public static void main(String[] args) throws Exception {
    DataSource dataSource = new DataSource();
    ScheduledExecutorService scheduledExecutor = Executors.newSingleThreadScheduledExecutor();
    CappedDatabase cappedDatabase = new CappedDatabase(new File("glowroot.capped.db"), 1000000,
            scheduledExecutor, Ticker.systemTicker());
    TraceDao traceDao = new TraceDao(dataSource, cappedDatabase, mock(TransactionTypeDao.class),
            mock(FullQueryTextDao.class), mock(TraceAttributeNameDao.class));

    Stopwatch stopwatch = Stopwatch.createStarted();
    for (int i = 0; i < 1000; i++) {
        traceDao.store(TraceTestData.createTraceReader());
    }//from   ww w.  j  a va 2s. c  o m
    logger.info("elapsed time: {}", stopwatch.elapsed(MILLISECONDS));
}

From source file:org.glowroot.sandbox.ui.TraceDaoDeletePerformanceMain.java

public static void main(String... args) throws Exception {
    Container container = Containers.createWithFileDb(new File("target"));
    container.executeAppUnderTest(GenerateTraces.class);
    int pendingWrites = container.getTraceService().getNumPendingCompleteTransactions();
    while (pendingWrites > 0) {
        logger.info("pending trace writes: {}", pendingWrites);
        Thread.sleep(1000);/* w  w  w .j  a  v a  2s.com*/
        pendingWrites = container.getTraceService().getNumPendingCompleteTransactions();
    }
    File dbFile = new File("target/glowroot.h2.db");
    long dbSize = dbFile.length();
    logger.info("glowroot.h2.db: {} bytes", dbSize);
    Stopwatch stopwatch = Stopwatch.createStarted();
    container.getTraceService().deleteAll();
    logger.info("all traces deleted in: {} millis", stopwatch.elapsed(MILLISECONDS));
    logger.info("glowroot.h2.db: {} bytes", dbFile.length());
    container.close();
    logger.info("glowroot.h2.db: {} bytes", dbFile.length());
}

From source file:nl.knaw.huygens.timbuctoo.tools.importer.base.LanguageConverter.java

public static void main(String[] args) throws Exception {
    Stopwatch stopWatch = Stopwatch.createStarted();

    // Handle commandline arguments
    String directoryName = (args.length > 0) ? args[0] : "../../timbuctoo-testdata/src/main/resources/general/";
    File directory = new File(directoryName);
    if (!directory.isDirectory()) {
        System.out.println("## Not a directory: " + directoryName);
        System.exit(-1);/*from   w w  w  .j  a v a  2 s  .  c  om*/
    }
    File languageFile = new File(directory, "iso-639-3.tab");
    if (!languageFile.canRead()) {
        System.out.println("## Can not read file: " + languageFile.getAbsolutePath());
        System.exit(-1);
    }

    File outputDirectory = new File("import/base");
    outputDirectory.mkdirs();
    File outputFile = new File(outputDirectory, "baselanguage.json");
    new LanguageConverter(outputFile).handleFile(languageFile, 0, false);

    System.out.printf("-- Time used: %s%n", stopWatch);
}

From source file:com.doctor.getting_started.UsingJava8BetterByUseMethodReference.java

public static void main(String[] args) {
    ExecutorService executor = Executors.newCachedThreadPool();
    int ringBufferSize = 1024;

    Disruptor<LongEvent> disruptor = new Disruptor<>(LongEvent::new, ringBufferSize, executor);
    disruptor.handleEventsWith(UsingJava8BetterByUseMethodReference::onEvent);
    disruptor.start();/*from  www. j a  v a2 s. co m*/

    ByteBuffer buffer = ByteBuffer.allocate(8);

    Stopwatch stopwatch = Stopwatch.createStarted();

    for (long i = 0; i < 10; i++) {
        buffer.putLong(0, i);
        disruptor.publishEvent(UsingJava8BetterByUseMethodReference::translateTo, buffer);
    }

    long elapsed = stopwatch.elapsed(TimeUnit.MICROSECONDS);
    System.out.println("elapsed:" + elapsed);
    stopwatch.stop();

    disruptor.shutdown();
    executor.shutdown();
}