List of usage examples for com.google.common.base Stopwatch elapsed
@CheckReturnValue public long elapsed(TimeUnit desiredUnit)
From source file:de.unentscheidbar.csv2.ProfileMe.java
public static void main(String[] args) throws Exception { File gofile = new File("go"); while (!gofile.exists()) { System.out.println("Waiting..."); Thread.sleep(1000);/* ww w . ja v a 2s .c o m*/ } double kibPerRun = csv.length() / 2048.0; System.out.println("go " + kibPerRun + " kib"); while (gofile.exists()) { Stopwatch sw = Stopwatch.createStarted(); long ops = operation(); long micros = sw.elapsed(TimeUnit.MICROSECONDS); System.out.println("@" + ((ops * kibPerRun / micros) * 1_000_000 / 1024.0) + " mbps"); } System.out.println("exiting"); }
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);//from ww w .j a va2 s . c o m 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:ch.ethz.tik.graphgenerator.GraphGenerator.java
public static void main(String[] args) { Stopwatch stopwatch = Stopwatch.createStarted(); Graph graph = generateGraph();//from w ww. j a v a2 s .c om stopwatch.elapsed(TimeUnit.MILLISECONDS); System.out.println("Reading and creating graph took: " + stopwatch); createExampleRoutes(graph); stopwatch = Stopwatch.createStarted(); GraphSerializerUtil.serializeGraph(graph, SERIALIZED_FILE_GRAPH); stopwatch.elapsed(TimeUnit.MILLISECONDS); System.out.println("Serialized graph in " + stopwatch); }
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 w ww.j a va2 s . co m logger.info("elapsed time: {}", stopwatch.elapsed(MILLISECONDS)); }
From source file:com.google.devtools.build.android.AndroidResourceParsingAction.java
public static void main(String[] args) throws Exception { OptionsParser optionsParser = OptionsParser.newOptionsParser(Options.class); optionsParser.parseAndExitUponError(args); Options options = optionsParser.getOptions(Options.class); Preconditions.checkNotNull(options.primaryData); Preconditions.checkNotNull(options.output); final Stopwatch timer = Stopwatch.createStarted(); ParsedAndroidData parsedPrimary = ParsedAndroidData.from(options.primaryData); logger.fine(String.format("Walked XML tree at %dms", timer.elapsed(TimeUnit.MILLISECONDS))); UnwrittenMergedAndroidData unwrittenData = UnwrittenMergedAndroidData.of(null, parsedPrimary, ParsedAndroidData.from(ImmutableList.<DependencyAndroidData>of())); AndroidDataSerializer serializer = AndroidDataSerializer.create(); unwrittenData.serializeTo(serializer); serializer.flushTo(options.output);//from w w w . j a va 2s .c o m logger.fine(String.format("Finished parse + serialize in %dms", timer.elapsed(TimeUnit.MILLISECONDS))); }
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();/* w w w . ja v a 2 s. c o m*/ 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());//w w w . ja v a2 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.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 ww w. j a v a 2 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(); }
From source file:com.jejking.hh.nord.app.CreateSpatialDrucksachenRepository.java
/** * Runs the main importer logic. Supply two parameters: directory where * the Neo4j database is located, directory where the serialised {@link RawDrucksache} * instances are to be found, each in its own file. * /*www .j a v a 2s . com*/ * @param args */ public static void main(String[] args) { Stopwatch stopwatch = Stopwatch.createStarted(); GraphDatabaseService graph = new GraphDatabaseFactory().newEmbeddedDatabase(args[0]); registerShutdownHook(graph); System.out.println("Started graph database after " + stopwatch.elapsed(TimeUnit.SECONDS) + " seconds"); DrucksachenGazetteerKeywordMatcherFactory matcherFactory = new DrucksachenGazetteerKeywordMatcherFactory(); ImmutableMap<String, DrucksachenGazetteerKeywordMatcher> matchersMap = matcherFactory .createKeywordMatchersFromGazetteer(graph, ImmutableList.of(GazetteerEntryTypes.NAMED_AREA, GazetteerEntryTypes.STREET, GazetteerEntryTypes.SCHOOL, GazetteerEntryTypes.HOSPITAL, GazetteerEntryTypes.CINEMA, GazetteerEntryTypes.UNIVERSITY)); ImportAndMatch importer = new ImportAndMatch(matchersMap); System.out.println("Initialised matchers after " + stopwatch.elapsed(TimeUnit.SECONDS) + " seconds"); importer.createDrucksachenIndexes(graph); System.out.println( "Created indexes for Drucksachen after " + stopwatch.elapsed(TimeUnit.SECONDS) + " seconds"); File drucksachenDirectory = new File(args[1]); importer.writeToNeo(Arrays.asList(drucksachenDirectory.listFiles()), graph); System.out.println("Completed import after " + stopwatch.elapsed(TimeUnit.SECONDS) + " seconds"); }
From source file:com.google.cloud.genomics.gatk.htsjdk.SamReaderExample.java
public static void main(String[] args) { try {/* w w w.j a v a2s . c o m*/ SamReaderFactory factory = SamReaderFactory.makeDefault(); // If it was a file, we would open like so: // factory.open(new File("~/testdata/htsjdk/samtools/uncompressed.sam")); // For API access we use SamInputResource constructed from a URL: SamReader reader = factory.open(SamInputResource.of(new URL(GA4GH_URL))); Stopwatch timer = Stopwatch.createStarted(); int processedReads = 0; for (@SuppressWarnings("unused") final SAMRecord samRecord : reader) { processedReads++; } final long elapsed = timer.elapsed(TimeUnit.MILLISECONDS); if (processedReads > 0 && elapsed > 0) { System.out.println("Processed " + processedReads + " reads in " + timer + ". Speed: " + (processedReads * 1000) / elapsed + " reads/sec"); } else { System.out.println("Nothing processed or not enough reads for timing stats."); } reader.close(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }