Java Code Examples for org.springframework.util.StopWatch

The following examples show how to use org.springframework.util.StopWatch. These examples are extracted from open source projects. 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 Project: spring4-understanding   Author: langtianya   File: BenchmarkTests.java    License: Apache License 2.0 6 votes vote down vote up
private long testAfterReturningAdviceWithoutJoinPoint(String file, int howmany, String technology) {
	ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file, CLASS);

	StopWatch sw = new StopWatch();
	sw.start(howmany + " repeated after returning advice invocations with " + technology);
	ITestBean adrian = (ITestBean) bf.getBean("adrian");

	assertTrue(AopUtils.isAopProxy(adrian));
	Advised a = (Advised) adrian;
	assertTrue(a.getAdvisors().length >= 3);
	// Hits joinpoint
	adrian.setAge(25);

	for (int i = 0; i < howmany; i++) {
		adrian.setAge(i);
	}

	sw.stop();
	System.out.println(sw.prettyPrint());
	return sw.getLastTaskTimeMillis();
}
 
Example #2
Source Project: spring-analysis-note   Author: Vip-Augus   File: AnnotationProcessorPerformanceTests.java    License: MIT License 6 votes vote down vote up
@Test
public void testPrototypeCreationWithResourcePropertiesIsFastEnough() {
	GenericApplicationContext ctx = new GenericApplicationContext();
	AnnotationConfigUtils.registerAnnotationConfigProcessors(ctx);
	ctx.refresh();

	RootBeanDefinition rbd = new RootBeanDefinition(ResourceAnnotatedTestBean.class);
	rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
	ctx.registerBeanDefinition("test", rbd);
	ctx.registerBeanDefinition("spouse", new RootBeanDefinition(TestBean.class));
	TestBean spouse = (TestBean) ctx.getBean("spouse");
	StopWatch sw = new StopWatch();
	sw.start("prototype");
	for (int i = 0; i < 100000; i++) {
		TestBean tb = (TestBean) ctx.getBean("test");
		assertSame(spouse, tb.getSpouse());
	}
	sw.stop();
	assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 4000);
}
 
Example #3
Source Project: spring-analysis-note   Author: Vip-Augus   File: AnnotationProcessorPerformanceTests.java    License: MIT License 6 votes vote down vote up
@Test
public void testPrototypeCreationWithAutowiredPropertiesIsFastEnough() {
	GenericApplicationContext ctx = new GenericApplicationContext();
	AnnotationConfigUtils.registerAnnotationConfigProcessors(ctx);
	ctx.refresh();

	RootBeanDefinition rbd = new RootBeanDefinition(AutowiredAnnotatedTestBean.class);
	rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
	ctx.registerBeanDefinition("test", rbd);
	ctx.registerBeanDefinition("spouse", new RootBeanDefinition(TestBean.class));
	TestBean spouse = (TestBean) ctx.getBean("spouse");
	StopWatch sw = new StopWatch();
	sw.start("prototype");
	for (int i = 0; i < 100000; i++) {
		TestBean tb = (TestBean) ctx.getBean("test");
		assertSame(spouse, tb.getSpouse());
	}
	sw.stop();
	assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 4000);
}
 
Example #4
Source Project: spring-analysis-note   Author: Vip-Augus   File: AnnotationProcessorPerformanceTests.java    License: MIT License 6 votes vote down vote up
@Test
public void testPrototypeCreationWithOverriddenAutowiredPropertiesIsFastEnough() {
	GenericApplicationContext ctx = new GenericApplicationContext();
	AnnotationConfigUtils.registerAnnotationConfigProcessors(ctx);
	ctx.refresh();

	RootBeanDefinition rbd = new RootBeanDefinition(AutowiredAnnotatedTestBean.class);
	rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
	rbd.getPropertyValues().add("spouse", new RuntimeBeanReference("spouse"));
	ctx.registerBeanDefinition("test", rbd);
	ctx.registerBeanDefinition("spouse", new RootBeanDefinition(TestBean.class));
	TestBean spouse = (TestBean) ctx.getBean("spouse");
	StopWatch sw = new StopWatch();
	sw.start("prototype");
	for (int i = 0; i < 100000; i++) {
		TestBean tb = (TestBean) ctx.getBean("test");
		assertSame(spouse, tb.getSpouse());
	}
	sw.stop();
	assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 6000);
}
 
Example #5
Source Project: spring4-understanding   Author: langtianya   File: BenchmarkTests.java    License: Apache License 2.0 6 votes vote down vote up
private long testBeforeAdviceWithoutJoinPoint(String file, int howmany, String technology) {
	ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file, CLASS);

	StopWatch sw = new StopWatch();
	sw.start(howmany + " repeated before advice invocations with " + technology);
	ITestBean adrian = (ITestBean) bf.getBean("adrian");

	assertTrue(AopUtils.isAopProxy(adrian));
	Advised a = (Advised) adrian;
	assertTrue(a.getAdvisors().length >= 3);
	assertEquals("adrian", adrian.getName());

	for (int i = 0; i < howmany; i++) {
		adrian.getName();
	}

	sw.stop();
	System.out.println(sw.prettyPrint());
	return sw.getLastTaskTimeMillis();
}
 
Example #6
Source Project: spring4-understanding   Author: langtianya   File: AnnotationProcessorPerformanceTests.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testPrototypeCreationWithAutowiredPropertiesIsFastEnough() {
	GenericApplicationContext ctx = new GenericApplicationContext();
	AnnotationConfigUtils.registerAnnotationConfigProcessors(ctx);
	ctx.refresh();

	RootBeanDefinition rbd = new RootBeanDefinition(AutowiredAnnotatedTestBean.class);
	rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
	ctx.registerBeanDefinition("test", rbd);
	ctx.registerBeanDefinition("spouse", new RootBeanDefinition(TestBean.class));
	TestBean spouse = (TestBean) ctx.getBean("spouse");
	StopWatch sw = new StopWatch();
	sw.start("prototype");
	for (int i = 0; i < 100000; i++) {
		TestBean tb = (TestBean) ctx.getBean("test");
		assertSame(spouse, tb.getSpouse());
	}
	sw.stop();
	assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 4000);
}
 
Example #7
Source Project: spring4-understanding   Author: langtianya   File: AnnotationProcessorPerformanceTests.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testPrototypeCreationWithOverriddenAutowiredPropertiesIsFastEnough() {
	GenericApplicationContext ctx = new GenericApplicationContext();
	AnnotationConfigUtils.registerAnnotationConfigProcessors(ctx);
	ctx.refresh();

	RootBeanDefinition rbd = new RootBeanDefinition(AutowiredAnnotatedTestBean.class);
	rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
	rbd.getPropertyValues().add("spouse", new RuntimeBeanReference("spouse"));
	ctx.registerBeanDefinition("test", rbd);
	ctx.registerBeanDefinition("spouse", new RootBeanDefinition(TestBean.class));
	TestBean spouse = (TestBean) ctx.getBean("spouse");
	StopWatch sw = new StopWatch();
	sw.start("prototype");
	for (int i = 0; i < 100000; i++) {
		TestBean tb = (TestBean) ctx.getBean("test");
		assertSame(spouse, tb.getSpouse());
	}
	sw.stop();
	assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 6000);
}
 
Example #8
Source Project: java-technology-stack   Author: codeEngraver   File: DefaultListableBeanFactoryTests.java    License: MIT License 6 votes vote down vote up
@Test
public void testSingletonLookupByNameIsFastEnough() {
	Assume.group(TestGroup.PERFORMANCE);
	Assume.notLogging(factoryLog);
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	lbf.registerBeanDefinition("test", new RootBeanDefinition(TestBean.class));
	lbf.freezeConfiguration();
	StopWatch sw = new StopWatch();
	sw.start("singleton");
	for (int i = 0; i < 1000000; i++) {
		lbf.getBean("test");
	}
	sw.stop();
	// System.out.println(sw.getTotalTimeMillis());
	assertTrue("Singleton lookup took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 1000);
}
 
Example #9
Source Project: spring-analysis-note   Author: Vip-Augus   File: GenericConversionServiceTests.java    License: MIT License 6 votes vote down vote up
@Test
public void testPerformance2() throws Exception {
	Assume.group(TestGroup.PERFORMANCE);
	StopWatch watch = new StopWatch("list<string> -> list<integer> conversionPerformance");
	watch.start("convert 4,000,000 with conversion service");
	List<String> source = new LinkedList<>();
	source.add("1");
	source.add("2");
	source.add("3");
	TypeDescriptor td = new TypeDescriptor(getClass().getField("list"));
	for (int i = 0; i < 1000000; i++) {
		conversionService.convert(source, TypeDescriptor.forObject(source), td);
	}
	watch.stop();
	watch.start("convert 4,000,000 manually");
	for (int i = 0; i < 4000000; i++) {
		List<Integer> target = new ArrayList<>(source.size());
		for (String element : source) {
			target.add(Integer.valueOf(element));
		}
	}
	watch.stop();
	// System.out.println(watch.prettyPrint());
}
 
Example #10
Source Project: spring-analysis-note   Author: Vip-Augus   File: MapAccessTests.java    License: MIT License 6 votes vote down vote up
@Test
public void testGetValuePerformance() throws Exception {
	Assume.group(TestGroup.PERFORMANCE);
	Map<String, String> map = new HashMap<>();
	map.put("key", "value");
	EvaluationContext context = new StandardEvaluationContext(map);

	ExpressionParser spelExpressionParser = new SpelExpressionParser();
	Expression expr = spelExpressionParser.parseExpression("#root['key']");

	StopWatch s = new StopWatch();
	s.start();
	for (int i = 0; i < 10000; i++) {
		expr.getValue(context);
	}
	s.stop();
	assertThat(s.getTotalTimeMillis(), lessThan(200L));
}
 
Example #11
Source Project: java-technology-stack   Author: codeEngraver   File: DefaultListableBeanFactoryTests.java    License: MIT License 6 votes vote down vote up
@Test
public void testPrototypeCreationIsFastEnough() {
	Assume.group(TestGroup.PERFORMANCE);
	Assume.notLogging(factoryLog);
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	RootBeanDefinition rbd = new RootBeanDefinition(TestBean.class);
	rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
	lbf.registerBeanDefinition("test", rbd);
	lbf.freezeConfiguration();
	StopWatch sw = new StopWatch();
	sw.start("prototype");
	for (int i = 0; i < 100000; i++) {
		lbf.getBean("test");
	}
	sw.stop();
	// System.out.println(sw.getTotalTimeMillis());
	assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 3000);
}
 
Example #12
Source Project: minicubes   Author: totyumengr   File: MiniCubeTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void test_5_2_DistinctCount_20140606() throws Throwable {
    
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    Map<String, List<Integer>> filter = new HashMap<String, List<Integer>>(1);
    filter.put("tradeId", Arrays.asList(new Integer[] {
        3205, 3206, 3207, 3208, 3209, 3210, 3212, 3299, 
        3204, 3203, 3202, 3201, 3211}));
    Map<Integer, RoaringBitmap> distinct = miniCube.distinct("postId", true, "tradeId", filter);
    stopWatch.stop();
    
    Assert.assertEquals(13, distinct.size());
    Assert.assertEquals(277, distinct.get(3209).getCardinality());
    Assert.assertEquals(186, distinct.get(3211).getCardinality());
    Assert.assertEquals(464, distinct.get(3206).getCardinality());
    LOGGER.info(stopWatch.getTotalTimeSeconds() + " used for distinct result {}", distinct.toString());
    
}
 
Example #13
Source Project: java-technology-stack   Author: codeEngraver   File: DefaultListableBeanFactoryTests.java    License: MIT License 6 votes vote down vote up
@Test
public void testPrototypeCreationWithDependencyCheckIsFastEnough() {
	Assume.group(TestGroup.PERFORMANCE);
	Assume.notLogging(factoryLog);
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	RootBeanDefinition rbd = new RootBeanDefinition(LifecycleBean.class);
	rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
	rbd.setDependencyCheck(RootBeanDefinition.DEPENDENCY_CHECK_OBJECTS);
	lbf.registerBeanDefinition("test", rbd);
	lbf.addBeanPostProcessor(new LifecycleBean.PostProcessor());
	lbf.freezeConfiguration();
	StopWatch sw = new StopWatch();
	sw.start("prototype");
	for (int i = 0; i < 100000; i++) {
		lbf.getBean("test");
	}
	sw.stop();
	// System.out.println(sw.getTotalTimeMillis());
	assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 3000);
}
 
Example #14
Source Project: secure-data-service   Author: inbloom   File: ZipFileIterator.java    License: Apache License 2.0 6 votes vote down vote up
public InputStream next() {
    ZipArchiveEntry zipEntry = zipEntries.nextElement();

    StopWatch sw = new StopWatch(zipEntry.getName());

    InputStream feStream = null;

    try {
        return zipFile.getInputStream(zipEntry);
    } catch (IOException e) {
        IOUtils.closeQuietly(feStream);

        return null;
    } finally {
        IOUtils.closeQuietly(feStream);

        System.out.print(sw.prettyPrint());
    }
}
 
Example #15
Source Project: spring-analysis-note   Author: Vip-Augus   File: DefaultListableBeanFactoryTests.java    License: MIT License 6 votes vote down vote up
@Test
public void testPrototypeCreationWithResolvedConstructorArgumentsIsFastEnough() {
	Assume.group(TestGroup.PERFORMANCE);
	Assume.notLogging(factoryLog);
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	RootBeanDefinition rbd = new RootBeanDefinition(TestBean.class);
	rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
	rbd.getConstructorArgumentValues().addGenericArgumentValue(new RuntimeBeanReference("spouse"));
	lbf.registerBeanDefinition("test", rbd);
	lbf.registerBeanDefinition("spouse", new RootBeanDefinition(TestBean.class));
	lbf.freezeConfiguration();
	TestBean spouse = (TestBean) lbf.getBean("spouse");
	StopWatch sw = new StopWatch();
	sw.start("prototype");
	for (int i = 0; i < 100000; i++) {
		TestBean tb = (TestBean) lbf.getBean("test");
		assertSame(spouse, tb.getSpouse());
	}
	sw.stop();
	// System.out.println(sw.getTotalTimeMillis());
	assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 4000);
}
 
Example #16
Source Project: spring-analysis-note   Author: Vip-Augus   File: DefaultListableBeanFactoryTests.java    License: MIT License 6 votes vote down vote up
@Test
public void testPrototypeCreationWithResolvedPropertiesIsFastEnough() {
	Assume.group(TestGroup.PERFORMANCE);
	Assume.notLogging(factoryLog);
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	RootBeanDefinition rbd = new RootBeanDefinition(TestBean.class);
	rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
	rbd.getPropertyValues().add("spouse", new RuntimeBeanReference("spouse"));
	lbf.registerBeanDefinition("test", rbd);
	lbf.registerBeanDefinition("spouse", new RootBeanDefinition(TestBean.class));
	lbf.freezeConfiguration();
	TestBean spouse = (TestBean) lbf.getBean("spouse");
	StopWatch sw = new StopWatch();
	sw.start("prototype");
	for (int i = 0; i < 100000; i++) {
		TestBean tb = (TestBean) lbf.getBean("test");
		assertSame(spouse, tb.getSpouse());
	}
	sw.stop();
	// System.out.println(sw.getTotalTimeMillis());
	assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 4000);
}
 
Example #17
Source Project: spring-cloud-gateway   Author: spring-cloud   File: AbstractHttpServer.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public final void stop() {
	synchronized (this.lifecycleMonitor) {
		if (isRunning()) {
			String serverName = getClass().getSimpleName();
			logger.debug("Stopping " + serverName + "...");
			this.running = false;
			try {
				StopWatch stopWatch = new StopWatch();
				stopWatch.start();
				stopInternal();
				logger.debug("Server stopped (" + stopWatch.getTotalTimeMillis()
						+ " millis).");
			}
			catch (Throwable ex) {
				throw new IllegalStateException(ex);
			}
			finally {
				reset();
			}
		}
	}
}
 
Example #18
Source Project: java-technology-stack   Author: codeEngraver   File: DefaultListableBeanFactoryTests.java    License: MIT License 6 votes vote down vote up
@Test
public void testPrototypeCreationWithResolvedConstructorArgumentsIsFastEnough() {
	Assume.group(TestGroup.PERFORMANCE);
	Assume.notLogging(factoryLog);
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	RootBeanDefinition rbd = new RootBeanDefinition(TestBean.class);
	rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
	rbd.getConstructorArgumentValues().addGenericArgumentValue(new RuntimeBeanReference("spouse"));
	lbf.registerBeanDefinition("test", rbd);
	lbf.registerBeanDefinition("spouse", new RootBeanDefinition(TestBean.class));
	lbf.freezeConfiguration();
	TestBean spouse = (TestBean) lbf.getBean("spouse");
	StopWatch sw = new StopWatch();
	sw.start("prototype");
	for (int i = 0; i < 100000; i++) {
		TestBean tb = (TestBean) lbf.getBean("test");
		assertSame(spouse, tb.getSpouse());
	}
	sw.stop();
	// System.out.println(sw.getTotalTimeMillis());
	assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 4000);
}
 
Example #19
Source Project: java-technology-stack   Author: codeEngraver   File: AnnotationProcessorPerformanceTests.java    License: MIT License 6 votes vote down vote up
@Test
public void testPrototypeCreationWithResourcePropertiesIsFastEnough() {
	GenericApplicationContext ctx = new GenericApplicationContext();
	AnnotationConfigUtils.registerAnnotationConfigProcessors(ctx);
	ctx.refresh();

	RootBeanDefinition rbd = new RootBeanDefinition(ResourceAnnotatedTestBean.class);
	rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
	ctx.registerBeanDefinition("test", rbd);
	ctx.registerBeanDefinition("spouse", new RootBeanDefinition(TestBean.class));
	TestBean spouse = (TestBean) ctx.getBean("spouse");
	StopWatch sw = new StopWatch();
	sw.start("prototype");
	for (int i = 0; i < 100000; i++) {
		TestBean tb = (TestBean) ctx.getBean("test");
		assertSame(spouse, tb.getSpouse());
	}
	sw.stop();
	assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 4000);
}
 
Example #20
Source Project: java-technology-stack   Author: codeEngraver   File: AbstractHttpServer.java    License: MIT License 6 votes vote down vote up
@Override
public final void stop() {
	synchronized (this.lifecycleMonitor) {
		if (isRunning()) {
			String serverName = getClass().getSimpleName();
			logger.debug("Stopping " + serverName + "...");
			this.running = false;
			try {
				StopWatch stopWatch = new StopWatch();
				stopWatch.start();
				stopInternal();
				logger.debug("Server stopped (" + stopWatch.getTotalTimeMillis() + " millis).");
			}
			catch (Throwable ex) {
				throw new IllegalStateException(ex);
			}
			finally {
				reset();
			}
		}
	}
}
 
Example #21
Source Project: java-technology-stack   Author: codeEngraver   File: DefaultListableBeanFactoryTests.java    License: MIT License 6 votes vote down vote up
@Test
@Ignore  // TODO re-enable when ConstructorResolver TODO sorted out
public void testPrototypeCreationWithConstructorArgumentsIsFastEnough() {
	Assume.group(TestGroup.PERFORMANCE);
	Assume.notLogging(factoryLog);
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	RootBeanDefinition rbd = new RootBeanDefinition(TestBean.class);
	rbd.setScope(RootBeanDefinition.SCOPE_PROTOTYPE);
	rbd.getConstructorArgumentValues().addGenericArgumentValue("juergen");
	rbd.getConstructorArgumentValues().addGenericArgumentValue("99");
	lbf.registerBeanDefinition("test", rbd);
	lbf.freezeConfiguration();
	StopWatch sw = new StopWatch();
	sw.start("prototype");
	for (int i = 0; i < 100000; i++) {
		TestBean tb = (TestBean) lbf.getBean("test");
		assertEquals("juergen", tb.getName());
		assertEquals(99, tb.getAge());
	}
	sw.stop();
	// System.out.println(sw.getTotalTimeMillis());
	assertTrue("Prototype creation took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 3000);
}
 
Example #22
Source Project: DevOps-for-Web-Development   Author: PacktPublishing   File: CallMonitoringAspect.java    License: MIT License 6 votes vote down vote up
@Around("within(@org.springframework.stereotype.Repository *)")
public Object invoke(ProceedingJoinPoint joinPoint) throws Throwable {
    if (this.enabled) {
        StopWatch sw = new StopWatch(joinPoint.toShortString());

        sw.start("invoke");
        try {
            return joinPoint.proceed();
        } finally {
            sw.stop();
            synchronized (this) {
                this.callCount++;
                this.accumulatedCallTime += sw.getTotalTimeMillis();
            }
        }
    } else {
        return joinPoint.proceed();
    }
}
 
Example #23
Source Project: java-technology-stack   Author: codeEngraver   File: DefaultListableBeanFactoryTests.java    License: MIT License 6 votes vote down vote up
@Test
public void testSingletonLookupByTypeIsFastEnough() {
	Assume.group(TestGroup.PERFORMANCE);
	Assume.notLogging(factoryLog);
	DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
	lbf.registerBeanDefinition("test", new RootBeanDefinition(TestBean.class));
	lbf.freezeConfiguration();
	StopWatch sw = new StopWatch();
	sw.start("singleton");
	for (int i = 0; i < 1000000; i++) {
		lbf.getBean(TestBean.class);
	}
	sw.stop();
	// System.out.println(sw.getTotalTimeMillis());
	assertTrue("Singleton lookup took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 1000);
}
 
Example #24
Source Project: java-technology-stack   Author: codeEngraver   File: BenchmarkTests.java    License: MIT License 6 votes vote down vote up
private long testAfterReturningAdviceWithoutJoinPoint(String file, int howmany, String technology) {
	ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file, CLASS);

	StopWatch sw = new StopWatch();
	sw.start(howmany + " repeated after returning advice invocations with " + technology);
	ITestBean adrian = (ITestBean) bf.getBean("adrian");

	assertTrue(AopUtils.isAopProxy(adrian));
	Advised a = (Advised) adrian;
	assertTrue(a.getAdvisors().length >= 3);
	// Hits joinpoint
	adrian.setAge(25);

	for (int i = 0; i < howmany; i++) {
		adrian.setAge(i);
	}

	sw.stop();
	System.out.println(sw.prettyPrint());
	return sw.getLastTaskTimeMillis();
}
 
Example #25
Source Project: java-technology-stack   Author: codeEngraver   File: DefaultConversionServiceTests.java    License: MIT License 6 votes vote down vote up
@Test
public void testPerformance1() {
	Assume.group(TestGroup.PERFORMANCE);
	StopWatch watch = new StopWatch("integer->string conversionPerformance");
	watch.start("convert 4,000,000 with conversion service");
	for (int i = 0; i < 4000000; i++) {
		conversionService.convert(3, String.class);
	}
	watch.stop();
	watch.start("convert 4,000,000 manually");
	for (int i = 0; i < 4000000; i++) {
		Integer.valueOf(3).toString();
	}
	watch.stop();
	// System.out.println(watch.prettyPrint());
}
 
Example #26
Source Project: java-technology-stack   Author: codeEngraver   File: MapAccessTests.java    License: MIT License 6 votes vote down vote up
@Test
public void testGetValuePerformance() throws Exception {
	Assume.group(TestGroup.PERFORMANCE);
	Map<String, String> map = new HashMap<>();
	map.put("key", "value");
	EvaluationContext context = new StandardEvaluationContext(map);

	ExpressionParser spelExpressionParser = new SpelExpressionParser();
	Expression expr = spelExpressionParser.parseExpression("#root['key']");

	StopWatch s = new StopWatch();
	s.start();
	for (int i = 0; i < 10000; i++) {
		expr.getValue(context);
	}
	s.stop();
	assertThat(s.getTotalTimeMillis(), lessThan(200L));
}
 
Example #27
Source Project: snomed-owl-toolkit   Author: IHTSDO   File: SnomedTaxonomyBuilder.java    License: Apache License 2.0 6 votes vote down vote up
public SnomedTaxonomy buildWithAxiomRefset(InputStreamSet snomedRf2OwlSnapshotArchive) throws ReleaseImportException {
	
	StopWatch stopWatch = new StopWatch();
	stopWatch.start();

	SnomedTaxonomyLoader snomedTaxonomyLoader = new SnomedTaxonomyLoader();
	
	ReleaseImporter releaseImporter = new ReleaseImporter();
	releaseImporter.loadEffectiveSnapshotReleaseFileStreams(snomedRf2OwlSnapshotArchive.getFileInputStreams(), OWL_SNAPSHOT_LOADING_PROFILE, snomedTaxonomyLoader);
	snomedTaxonomyLoader.reportErrors();
	logger.info("Loaded release snapshot");
	logger.info("Time taken deserialising axioms {}s", (snomedTaxonomyLoader.getTimeTakenDeserialisingAxioms() / 1000.00));
	
	stopWatch.stop();
	logger.info("SnomedTaxonomy loaded in {} seconds", stopWatch.getTotalTimeSeconds());

	SnomedTaxonomy snomedTaxonomy = snomedTaxonomyLoader.getSnomedTaxonomy();
	logger.info("{} concepts loaded", snomedTaxonomy.getAllConceptIds().size());
	logger.info("{} active axioms loaded", snomedTaxonomy.getAxiomCount());
	return snomedTaxonomy;

}
 
Example #28
Source Project: java-microservice   Author: apssouza22   File: CallMonitoringAspect.java    License: MIT License 6 votes vote down vote up
@Around("@annotation(com.apssouza.monitoring.Monitored)")
public Object invoke(ProceedingJoinPoint joinPoint) throws Throwable {
    System.out.println("callend");
    Method method = ((MethodSignature) joinPoint.getSignature()).getMethod();
    if (this.enabled) {
        StopWatch sw = new StopWatch(joinPoint.toShortString());

        sw.start("invoke");
        try {
            return joinPoint.proceed();
        } finally {
            sw.stop();
            synchronized (this) {
                this.callCount++;
                this.accumulatedCallTime += sw.getTotalTimeMillis();
            }
            publisher.publishEvent(new MonitoringInvokedEvent(
                    method.getName(),
                    this.accumulatedCallTime
            ));
        }
    } else {
        return joinPoint.proceed();
    }
}
 
Example #29
Source Project: NetworkDisk_Storage   Author: quhailong   File: EdgeServiceController.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * 生成公钥
 *
 * @author: quhailong
 * @date: 2019/9/26
 */
//@RequestMapping(value = "getPublickKey", method = {RequestMethod.GET})
@RequestMapping(value = "getpublickey", method = RequestMethod.GET)
public RestAPIResult<String> getPublicKey() throws Exception {
    logger.info("生成公钥请求URL:{}", httpServletRequest.getRequestURL());
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    logger.info("生成公钥数据处理开始");
    RestAPIResult<String> result = edgeServiceProvider.getPublicKeyHandle();
    logger.info("生成公钥数据处理结束,result:{}", result);
    stopWatch.stop();
    logger.info("生成公钥调用时间,millies:{}", stopWatch.getTotalTimeMillis());
    return result;
}
 
Example #30
Source Project: spring-analysis-note   Author: Vip-Augus   File: CustomizableTraceInterceptor.java    License: MIT License 5 votes vote down vote up
/**
 * Writes a log message before the invocation based on the value of {@code enterMessage}.
 * If the invocation succeeds, then a log message is written on exit based on the value
 * {@code exitMessage}. If an exception occurs during invocation, then a message is
 * written based on the value of {@code exceptionMessage}.
 * @see #setEnterMessage
 * @see #setExitMessage
 * @see #setExceptionMessage
 */
@Override
protected Object invokeUnderTrace(MethodInvocation invocation, Log logger) throws Throwable {
	String name = ClassUtils.getQualifiedMethodName(invocation.getMethod());
	StopWatch stopWatch = new StopWatch(name);
	Object returnValue = null;
	boolean exitThroughException = false;
	try {
		stopWatch.start(name);
		writeToLog(logger,
				replacePlaceholders(this.enterMessage, invocation, null, null, -1));
		returnValue = invocation.proceed();
		return returnValue;
	}
	catch (Throwable ex) {
		if (stopWatch.isRunning()) {
			stopWatch.stop();
		}
		exitThroughException = true;
		writeToLog(logger, replacePlaceholders(
				this.exceptionMessage, invocation, null, ex, stopWatch.getTotalTimeMillis()), ex);
		throw ex;
	}
	finally {
		if (!exitThroughException) {
			if (stopWatch.isRunning()) {
				stopWatch.stop();
			}
			writeToLog(logger, replacePlaceholders(
					this.exitMessage, invocation, returnValue, null, stopWatch.getTotalTimeMillis()));
		}
	}
}