Java Code Examples for org.apache.commons.lang3.time.StopWatch#start()
The following examples show how to use
org.apache.commons.lang3.time.StopWatch#start() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RidgeLogisticTrainerTest.java From pyramid with Apache License 2.0 | 6 votes |
private static void test3() throws Exception{ ClfDataSet dataSet = TRECFormat.loadClfDataSet(new File(DATASETS, "20newsgroup/1/train.trec"), DataSetType.CLF_SPARSE, true); ClfDataSet testSet = TRECFormat.loadClfDataSet(new File(DATASETS, "20newsgroup/1/test.trec"), DataSetType.CLF_SPARSE, true); System.out.println(dataSet.getMetaInfo()); RidgeLogisticTrainer trainer = RidgeLogisticTrainer.getBuilder() .setEpsilon(0.01) .setGaussianPriorVariance(0.5) .setHistory(5) .build(); StopWatch stopWatch = new StopWatch(); stopWatch.start(); LogisticRegression logisticRegression = trainer.train(dataSet); System.out.println(stopWatch); System.out.println("train: "+ Accuracy.accuracy(logisticRegression, dataSet)); System.out.println("test: "+Accuracy.accuracy(logisticRegression,testSet)); }
Example 2
Source File: AbstractUnstatefullJob.java From liteflow with Apache License 2.0 | 6 votes |
public void execute(){ try { if(isRunning.get()){ return; } isRunning.set(true); StopWatch stopWatch = new StopWatch(); stopWatch.start(); LOG.info("job start"); executeInternal(); LOG.info("job finished, takes {} ms", stopWatch.getTime()); } catch (Exception e) { LOG.error("run error", e); }finally{ isRunning.set(false); } }
Example 3
Source File: PerformanceMonitor.java From springboot-seed with MIT License | 6 votes |
/** * Monitor the elapsed time of method on controller layer, in * order to detect performance problems as soon as possible. * If elapsed time > 1 s, log it as an error. Otherwise, log it * as an info. */ @Around("controllerLayer()") public Object monitorElapsedTime(ProceedingJoinPoint proceedingJoinPoint) throws Throwable { // Timing the method in controller layer StopWatch stopWatch = new StopWatch(); stopWatch.start(); Object result = proceedingJoinPoint.proceed(); stopWatch.stop(); // Log the elapsed time double elapsedTime = stopWatch.getTime() / 1000.0; Signature signature = proceedingJoinPoint.getSignature(); String infoString = "[" + signature.toShortString() + "][Elapsed time: " + elapsedTime + " s]"; if (elapsedTime > 1) { log.error(infoString + "[Note that it's time consuming!]"); } else { log.info(infoString); } // Return the result return result; }
Example 4
Source File: LoginHelper.java From uyuni with GNU General Public License v2.0 | 6 votes |
/** * Schedule update of the errata cache for a given organization. * * @param orgIn organization */ private static void publishUpdateErrataCacheEvent(Org orgIn) { StopWatch sw = new StopWatch(); if (log.isDebugEnabled()) { log.debug("Updating errata cache"); sw.start(); } UpdateErrataCacheEvent uece = new UpdateErrataCacheEvent(UpdateErrataCacheEvent.TYPE_ORG); uece.setOrgId(orgIn.getId()); MessageQueue.publish(uece); if (log.isDebugEnabled()) { sw.stop(); log.debug("Finished Updating errata cache. Took [" + sw.getTime() + "]"); } }
Example 5
Source File: DefaultRender.java From poi-tl with Apache License 2.0 | 6 votes |
@Override public void render(XWPFTemplate template, Object root) { Objects.requireNonNull(template, "Template must not be null."); Objects.requireNonNull(root, "Data root must not be null"); LOGGER.info("Render template start..."); RenderDataCompute renderDataCompute = template.getConfig().getRenderDataComputeFactory().newCompute(root); StopWatch watch = new StopWatch(); try { watch.start(); renderReference(template); renderTemplate(template, renderDataCompute); renderInclude(template, renderDataCompute); } catch (Exception e) { if (e instanceof RenderException) throw (RenderException)e; throw new RenderException("Cannot render docx template, please check the Exception", e); } finally { watch.stop(); } LOGGER.info("Successfully Render template in {} millis", TimeUnit.NANOSECONDS.toMillis(watch.getNanoTime())); }
Example 6
Source File: AdaBoostMHTest.java From pyramid with Apache License 2.0 | 6 votes |
static void test1() throws Exception{ MultiLabelClfDataSet dataSet = TRECFormat.loadMultiLabelClfDataSet(new File(DATASETS, "ohsumed/3/train.trec"), DataSetType.ML_CLF_SPARSE, true); MultiLabelClfDataSet testSet = TRECFormat.loadMultiLabelClfDataSet(new File(DATASETS, "ohsumed/3/test.trec"), DataSetType.ML_CLF_SPARSE, true); AdaBoostMH boosting = new AdaBoostMH(dataSet.getNumClasses()); AdaBoostMHTrainer trainer = new AdaBoostMHTrainer(dataSet,boosting); StopWatch stopWatch = new StopWatch(); stopWatch.start(); for (int round =0;round<500;round++){ System.out.println("round="+round); trainer.iterate(); System.out.println(stopWatch); } System.out.println("training accuracy="+ Accuracy.accuracy(boosting, dataSet)); System.out.println("training overlap = "+ Overlap.overlap(boosting,dataSet)); System.out.println("test accuracy="+ Accuracy.accuracy(boosting, testSet)); System.out.println("test overlap = "+ Overlap.overlap(boosting,testSet)); }
Example 7
Source File: OperationStats.java From soundwave with Apache License 2.0 | 5 votes |
public OperationStats(String methodName, String statsName, Map<String, String> tags) { this.methodName = methodName; this.statsName = statsName; this.tags = tags; Stats.incr(StatsUtil.getStatsName(methodName, statsName, tags)); watch = new StopWatch(); watch.start(); }
Example 8
Source File: MeasureElapsedTime.java From levelup-java-examples with Apache License 2.0 | 5 votes |
@Test public void calculate_elapsed_time_in_apache_commons () throws InterruptedException { StopWatch stopWatch = new StopWatch(); stopWatch.start(); Thread.sleep(2); // simulate work stopWatch.stop(); long millis = stopWatch.getNanoTime(); logger.info("time: " + millis); assertTrue(millis >= 0); }
Example 9
Source File: RidgeLogisticOptimizerTest.java From pyramid with Apache License 2.0 | 5 votes |
private static void test4() throws Exception{ // ClfDataSet dataSet = TRECFormat.loadClfDataSet(new File(DATASETS, "/imdb/3/train.trec"), // DataSetType.CLF_SPARSE, true); // ClfDataSet testSet = TRECFormat.loadClfDataSet(new File(DATASETS, "/imdb/3/test.trec"), // DataSetType.CLF_SPARSE, true); ClfDataSet dataSet = TRECFormat.loadClfDataSet(new File(DATASETS, "20newsgroup/1/train.trec"), DataSetType.CLF_SPARSE, true); ClfDataSet testSet = TRECFormat.loadClfDataSet(new File(DATASETS, "20newsgroup/1/test.trec"), DataSetType.CLF_SPARSE, true); // ClfDataSet dataSet = TRECFormat.loadClfDataSet(new File(DATASETS, "/spam/trec_data/train.trec"), // DataSetType.CLF_SPARSE, true); // ClfDataSet testSet = TRECFormat.loadClfDataSet(new File(DATASETS, "/spam/trec_data/test.trec"), // DataSetType.CLF_SPARSE, true); double variance =1000; LogisticRegression logisticRegression = new LogisticRegression(dataSet.getNumClasses(),dataSet.getNumFeatures()); double[] weights = new double[dataSet.getNumDataPoints()]; for (int i=0;i<weights.length;i++){ if (Math.random()<0.1){ weights[i] = 0; } else { weights[i] = 1; } } RidgeLogisticOptimizer optimizer = new RidgeLogisticOptimizer(logisticRegression, dataSet, dataSet.getLabels(),weights, variance, true); System.out.println("after initialization"); System.out.println("train acc = " + Accuracy.accuracy(logisticRegression, dataSet)); System.out.println("test acc = "+Accuracy.accuracy(logisticRegression,testSet)); StopWatch stopWatch = new StopWatch(); stopWatch.start(); for (int i=0;i<20;i++){ ((LBFGS)optimizer.getOptimizer()).iterate(); System.out.println("after iteration "+i); System.out.println(stopWatch); // System.out.println("train acc = " + Accuracy.accuracy(logisticRegression, dataSet)); // System.out.println("test acc = "+Accuracy.accuracy(logisticRegression,testSet)); // System.out.println(logisticRegression); } }
Example 10
Source File: EntityIndexTest.java From usergrid with Apache License 2.0 | 5 votes |
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 } ); }
Example 11
Source File: RidgeLogisticOptimizerTest.java From pyramid with Apache License 2.0 | 5 votes |
private static void test3() throws Exception{ // ClfDataSet dataSet = TRECFormat.loadClfDataSet(new File(DATASETS, "/imdb/3/train.trec"), // DataSetType.CLF_SPARSE, true); // ClfDataSet testSet = TRECFormat.loadClfDataSet(new File(DATASETS, "/imdb/3/test.trec"), // DataSetType.CLF_SPARSE, true); ClfDataSet dataSet = TRECFormat.loadClfDataSet(new File(DATASETS, "20newsgroup/1/train.trec"), DataSetType.CLF_SPARSE, true); ClfDataSet testSet = TRECFormat.loadClfDataSet(new File(DATASETS, "20newsgroup/1/test.trec"), DataSetType.CLF_SPARSE, true); // ClfDataSet dataSet = TRECFormat.loadClfDataSet(new File(DATASETS, "/spam/trec_data/train.trec"), // DataSetType.CLF_SPARSE, true); // ClfDataSet testSet = TRECFormat.loadClfDataSet(new File(DATASETS, "/spam/trec_data/test.trec"), // DataSetType.CLF_SPARSE, true); double variance =1000; LogisticRegression logisticRegression = new LogisticRegression(dataSet.getNumClasses(),dataSet.getNumFeatures()); Optimizable.ByGradientValue loss = new LogisticLoss(logisticRegression,dataSet, variance, true); // GradientDescent optimizer = new GradientDescent(loss); LBFGS optimizer = new LBFGS(loss); System.out.println("after initialization"); System.out.println("train acc = " + Accuracy.accuracy(logisticRegression, dataSet)); System.out.println("test acc = "+Accuracy.accuracy(logisticRegression,testSet)); StopWatch stopWatch = new StopWatch(); stopWatch.start(); for (int i=0;i<200;i++){ optimizer.iterate(); System.out.println("after iteration "+i); System.out.println("loss = "+loss.getValue()); System.out.println("train acc = " + Accuracy.accuracy(logisticRegression, dataSet)); System.out.println("test acc = "+Accuracy.accuracy(logisticRegression,testSet)); // System.out.println(logisticRegression); } }
Example 12
Source File: TestBulkWithout.java From sqlg with MIT License | 5 votes |
@Test public void testBulkWithinMultipleHasContainers() throws InterruptedException { StopWatch stopWatch = new StopWatch(); stopWatch.start(); Vertex god = this.sqlgGraph.addVertex(T.label, "God"); Vertex person1 = this.sqlgGraph.addVertex(T.label, "Person", "idNumber", 1, "name", "pete"); god.addEdge("creator", person1); Vertex person2 = this.sqlgGraph.addVertex(T.label, "Person", "idNumber", 2, "name", "pete"); god.addEdge("creator", person2); Vertex person3 = this.sqlgGraph.addVertex(T.label, "Person", "idNumber", 3, "name", "john"); god.addEdge("creator", person3); Vertex person4 = this.sqlgGraph.addVertex(T.label, "Person", "idNumber", 4, "name", "pete"); god.addEdge("creator", person4); Vertex person5 = this.sqlgGraph.addVertex(T.label, "Person", "idNumber", 5, "name", "pete"); god.addEdge("creator", person5); Vertex person6 = this.sqlgGraph.addVertex(T.label, "Person", "idNumber", 6, "name", "pete"); god.addEdge("creator", person6); Vertex person7 = this.sqlgGraph.addVertex(T.label, "Person", "idNumber", 7, "name", "pete"); god.addEdge("creator", person7); Vertex person8 = this.sqlgGraph.addVertex(T.label, "Person", "idNumber", 8, "name", "pete"); god.addEdge("creator", person8); Vertex person9 = this.sqlgGraph.addVertex(T.label, "Person", "idNumber", 9, "name", "pete"); god.addEdge("creator", person9); Vertex person10 = this.sqlgGraph.addVertex(T.label, "Person", "idNumber", 10, "name", "pete"); god.addEdge("creator", person10); this.sqlgGraph.tx().commit(); stopWatch.stop(); System.out.println(stopWatch.toString()); stopWatch.reset(); stopWatch.start(); testBulkWithinMultipleHasContainers_assert(this.sqlgGraph); if (this.sqlgGraph1 != null) { Thread.sleep(SLEEP_TIME); testBulkWithinMultipleHasContainers_assert(this.sqlgGraph1); } stopWatch.stop(); System.out.println(stopWatch.toString()); }
Example 13
Source File: StreamWindowManagerImpl.java From eagle with Apache License 2.0 | 5 votes |
private void closeAndRemoveWindow(StreamWindow windowBucket) { StopWatch stopWatch = new StopWatch(); stopWatch.start(); closeWindow(windowBucket); removeWindow(windowBucket); stopWatch.stop(); LOG.info("Removed {} in {} ms", windowBucket, stopWatch.getTime()); }
Example 14
Source File: DBPopulatorRunner.java From gazpachoquest with GNU General Public License v3.0 | 5 votes |
public static void main(final String... args) { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("dbpopulator-datasource-context.xml", "dbpopulator-jpa-context.xml", "services-context.xml", "facades-context.xml", "components-context.xml"); DBPopulator populator = ctx.getBean(DBPopulator.class); StopWatch stopWatch = new StopWatch(); logger.info("Populating database"); stopWatch.start(); ShiroLogin.login(); populator.populate(); stopWatch.stop(); ShiroLogin.logout(); logger.info("Database populated in {} {}", stopWatch.getTime(), "ms"); ctx.close(); }
Example 15
Source File: HoverflyApiLiveTest.java From tutorials with MIT License | 5 votes |
@Test public void givenPostCourse_whenDelayInRequest_thenResponseIsDelayed() throws URISyntaxException { StopWatch stopWatch = new StopWatch(); stopWatch.start(); final ResponseEntity<Void> postResponse = restTemplate.postForEntity("http://www.baeldung.com/api/courses", null, Void.class); stopWatch.stop(); long postTime = stopWatch.getTime(); assertEquals(HttpStatus.OK, postResponse.getStatusCode()); assertTrue(3L <= TimeUnit.MILLISECONDS.toSeconds(postTime)); }
Example 16
Source File: TsneTest.java From deeplearning4j with Apache License 2.0 | 4 votes |
@Ignore @Test public void testTSNEPerformance() throws Exception { for (WorkspaceMode wsm : new WorkspaceMode[]{WorkspaceMode.NONE, WorkspaceMode.ENABLED}) { //STEP 1: Initialization int iterations = 50; //create an n-dimensional array of doubles Nd4j.setDataType(DataType.DOUBLE); List<String> cacheList = new ArrayList<>(); //cacheList is a dynamic array of strings used to hold all words //STEP 2: Turn text input into a list of words INDArray weights = Nd4j.rand(10000,300); StopWatch watch = new StopWatch(); watch.start(); //STEP 3: build a dual-tree tsne to use later log.info("Build model...."); BarnesHutTsne tsne = new BarnesHutTsne.Builder() .setMaxIter(iterations) .theta(0.5) .normalize(false) .learningRate(500) .useAdaGrad(false) .workspaceMode(wsm) .build(); watch.stop(); System.out.println("Elapsed time for construction: " + watch); //STEP 4: establish the tsne values and save them to a file log.info("Store TSNE Coordinates for Plotting...."); File outDir = testDir.newFolder(); watch.reset(); watch.start(); tsne.fit(weights); watch.stop(); System.out.println("Elapsed time for fit: " + watch); tsne.saveAsFile(cacheList, new File(outDir, "out.txt").getAbsolutePath()); } }
Example 17
Source File: FormatBenchmark.java From metrics with Apache License 2.0 | 4 votes |
private static void test(MetricFormat format) { System.out.println("====== test toString========="); System.out.println("format:" + format.getClass().getSimpleName()); RollingFileAppender appender = RollingFileAppender.builder() .name("metrics/metrics.log") .fileSize(1024 * 1024 * 300) .build(); Map<String, String> tags = new HashMap<String, String>(); tags.put("host", "127.0.0.1"); tags.put("appName", "hello" + random.nextInt()); tags.put("oooooooooooo", "pppppppppp" + random.nextInt()); tags.put("level" + random.nextInt(), "aaaaaaaa"); // MetricObject metricObject = MetricObject.named("abc" + random.nextInt()).withTimestamp(System.currentTimeMillis()) // .withValue("1321lkj12kl4jsdklfjdsf" + random.nextInt()).withTags(tags ).build(); int counter = 1000000; long lengthCounter = 0; StopWatch watch = new StopWatch(); watch.start(); for(int i = 0; i < counter; ++i) { MetricObject metricObject = MetricObject.named("abc" + random.nextInt()).withTimestamp(random.nextLong()) .withValue("1321lkj12kl4jsdklfjdsf" + random.nextInt()).withTags(tags ).build(); String string = format.format(metricObject); lengthCounter += string.length(); // appender.append(string); } watch.stop(); System.out.println(watch); System.out.println("length:" + lengthCounter/counter); System.out.println("qps:" + counter/(watch.getTime()/1000.0)); }
Example 18
Source File: FlexCollection.java From owltools with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public Iterator<FlexDocument> iterator() { final StopWatch timer = new StopWatch(); Set<OWLObject> blacklist = new HashSet<>(); blacklist.add(graph.getDataFactory().getOWLThing()); blacklist.add(graph.getDataFactory().getOWLNothing()); Set<OWLObject> allOWLObjects = graph.getAllOWLObjects().stream().filter(x -> !blacklist.contains(x)).collect(Collectors.toSet()); final int totalCount = allOWLObjects.size(); timer.start(); final Iterator<OWLObject> objectIterator = allOWLObjects.iterator(); return new Iterator<FlexDocument>() { int counter = 0; @Override public void remove() { throw new UnsupportedOperationException(); } @Override public FlexDocument next() { OWLObject obj = objectIterator.next(); FlexDocument doc = wring(obj, config); counter++; if( counter % 1000 == 0 ){ long elapsed = timer.getTime(); long eta = ((long)totalCount-counter) * (elapsed/((long)counter)); LOG.info("Loaded: " + Integer.toString(counter) + " of " + Integer.toString(totalCount) + ", elapsed: "+DurationFormatUtils.formatDurationHMS((elapsed)) + ", eta: "+DurationFormatUtils.formatDurationHMS(eta)); } return doc; } @Override public boolean hasNext() { return objectIterator.hasNext(); } }; }
Example 19
Source File: CalcOptimalKmer.java From RAMPART with GNU General Public License v3.0 | 3 votes |
@Override public TaskResult executeSample(Mecq.Sample sample, ExecutionContext executionContext) throws ProcessExecutionException, InterruptedException, IOException { StopWatch stopWatch = new StopWatch(); stopWatch.start(); Args args = this.getArgs(); List<ExecutionResult> results = new ArrayList<>(); this.kg2FileMap.clear(); this.mass2OptimalKmerMap.clear(); // Execute each config for (Map.Entry<String, List<Library>> entry : args.getKg2inputsMap().entrySet()) { File kgOutputDir = new File(args.getStageDir(sample), entry.getKey()); File kgOutputFile = new File(kgOutputDir, "kmergenie_results.log"); kg2FileMap.put(entry.getKey(), kgOutputFile); // Ensure output directory for this MASS run exists if (!kgOutputDir.exists() && !kgOutputDir.mkdirs()) { throw new IOException("Couldn't create kmer genie output directory at: " + kgOutputDir.getAbsolutePath()); } ExecutionResult result = this.executeKmerGenie(kgOutputDir, kgOutputFile, entry.getValue()); result.setName("kmergenie-" + entry.getKey()); results.add(result); } stopWatch.stop(); return new DefaultTaskResult(sample.name + "-" + args.stage.getOutputDirName(), true, results, stopWatch.getTime() / 1000L); }
Example 20
Source File: RegTreeTrainerTest.java From pyramid with Apache License 2.0 | 3 votes |
/** * slice location data, sparse */ static void test4() throws Exception { int numLeaves = 4; RegDataSet dataSet = StandardFormat.loadRegDataSet("/Users/chengli/Datasets/slice_location/standard/features.txt", "/Users/chengli/Datasets/slice_location/standard/labels.txt", ",", DataSetType.REG_SPARSE,false); System.out.println(dataSet.isDense()); int[] activeFeatures = IntStream.range(0, dataSet.getNumFeatures()).toArray(); int[] activeDataPoints = IntStream.range(0,dataSet.getNumDataPoints()).toArray(); RegTreeConfig regTreeConfig = new RegTreeConfig(); regTreeConfig.setMaxNumLeaves(numLeaves); regTreeConfig.setMinDataPerLeaf(5); regTreeConfig.setNumSplitIntervals(100); StopWatch stopWatch = new StopWatch(); stopWatch.start(); RegressionTree regressionTree = RegTreeTrainer.fit(regTreeConfig,dataSet); System.out.println(stopWatch); double mseValue = MSE.mse(regressionTree, dataSet); System.out.println(mseValue); System.out.println(regressionTree.getNumLeaves()); // System.out.println(regressionTree); // System.out.println(regressionTree.getRootReduction() ); }