Java Code Examples for org.springframework.util.StopWatch#getLastTaskTimeMillis()

The following examples show how to use org.springframework.util.StopWatch#getLastTaskTimeMillis() . 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: BenchmarkTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
private long testRepeatedAroundAdviceInvocations(String file, int howmany, String technology) {
	ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file, CLASS);

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

	assertTrue(AopUtils.isAopProxy(adrian));
	assertEquals(68, adrian.getAge());

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

	sw.stop();
	System.out.println(sw.prettyPrint());
	return sw.getLastTaskTimeMillis();
}
 
Example 2
Source File: BenchmarkTests.java    From spring-analysis-note with MIT License 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 3
Source File: BenchmarkTests.java    From spring-analysis-note with 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 4
Source File: BenchmarkTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
private long testRepeatedAroundAdviceInvocations(String file, int howmany, String technology) {
	ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file, CLASS);

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

	assertTrue(AopUtils.isAopProxy(adrian));
	assertEquals(68, adrian.getAge());

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

	sw.stop();
	System.out.println(sw.prettyPrint());
	return sw.getLastTaskTimeMillis();
}
 
Example 5
Source File: BenchmarkTests.java    From java-technology-stack with MIT License 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 File: BenchmarkTests.java    From java-technology-stack with 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 7
Source File: BenchmarkTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
private long testRepeatedAroundAdviceInvocations(String file, int howmany, String technology) {
	ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file, CLASS);

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

	assertTrue(AopUtils.isAopProxy(adrian));
	assertEquals(68, adrian.getAge());

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

	sw.stop();
	System.out.println(sw.prettyPrint());
	return sw.getLastTaskTimeMillis();
}
 
Example 8
Source File: BenchmarkTests.java    From spring4-understanding with 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 9
Source File: BenchmarkTests.java    From spring4-understanding with 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 10
Source File: BenchmarkTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private long testMix(String file, int howmany, String technology) {
	ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file, CLASS);

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

	assertTrue(AopUtils.isAopProxy(adrian));
	Advised a = (Advised) adrian;
	assertTrue(a.getAdvisors().length >= 3);

	for (int i = 0; i < howmany; i++) {
		// Hit all 3 joinpoints
		adrian.getAge();
		adrian.getName();
		adrian.setAge(i);

		// Invoke three non-advised methods
		adrian.getDoctor();
		adrian.getLawyer();
		adrian.getSpouse();
	}

	sw.stop();
	System.out.println(sw.prettyPrint());
	return sw.getLastTaskTimeMillis();
}
 
Example 11
Source File: BenchmarkTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
private long testMix(String file, int howmany, String technology) {
	ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file, CLASS);

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

	assertTrue(AopUtils.isAopProxy(adrian));
	Advised a = (Advised) adrian;
	assertTrue(a.getAdvisors().length >= 3);

	for (int i = 0; i < howmany; i++) {
		// Hit all 3 joinpoints
		adrian.getAge();
		adrian.getName();
		adrian.setAge(i);

		// Invoke three non-advised methods
		adrian.getDoctor();
		adrian.getLawyer();
		adrian.getSpouse();
	}

	sw.stop();
	System.out.println(sw.prettyPrint());
	return sw.getLastTaskTimeMillis();
}
 
Example 12
Source File: TimerAspect.java    From jigsaw-payment with Apache License 2.0 5 votes vote down vote up
public T measure(ProceedingJoinPoint joinPoint) throws Throwable {
	final StopWatch stopWatch = new StopWatch();
	stopWatch.start();

	@SuppressWarnings("unchecked")
	final T result = (T) joinPoint.proceed();

	stopWatch.stop();
	final long duration = stopWatch.getLastTaskTimeMillis();

	String log = this.buildLog(joinPoint, duration);
	logger.debug(log);
	submit(duration);
	return result;
}
 
Example 13
Source File: BenchmarkTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
private long testMix(String file, int howmany, String technology) {
	ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file, CLASS);

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

	assertTrue(AopUtils.isAopProxy(adrian));
	Advised a = (Advised) adrian;
	assertTrue(a.getAdvisors().length >= 3);

	for (int i = 0; i < howmany; i++) {
		// Hit all 3 joinpoints
		adrian.getAge();
		adrian.getName();
		adrian.setAge(i);

		// Invoke three non-advised methods
		adrian.getDoctor();
		adrian.getLawyer();
		adrian.getSpouse();
	}

	sw.stop();
	System.out.println(sw.prettyPrint());
	return sw.getLastTaskTimeMillis();
}
 
Example 14
Source File: AbstractPropertyAccessorTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Test
public void setPrimitiveArrayPropertyLargeMatching() {
	Assume.group(TestGroup.PERFORMANCE);
	Assume.notLogging(LogFactory.getLog(AbstractPropertyAccessorTests.class));

	PrimitiveArrayBean target = new PrimitiveArrayBean();
	AbstractPropertyAccessor accessor = createAccessor(target);
	int[] input = new int[1024];
	StopWatch sw = new StopWatch();
	sw.start("array1");
	for (int i = 0; i < 1000; i++) {
		accessor.setPropertyValue("array", input);
	}
	sw.stop();
	assertEquals(1024, target.getArray().length);
	assertEquals(0, target.getArray()[0]);
	long time1 = sw.getLastTaskTimeMillis();
	assertTrue("Took too long", sw.getLastTaskTimeMillis() < 100);

	accessor.registerCustomEditor(String.class, new StringTrimmerEditor(false));
	sw.start("array2");
	for (int i = 0; i < 1000; i++) {
		accessor.setPropertyValue("array", input);
	}
	sw.stop();
	assertTrue("Took too long", sw.getLastTaskTimeMillis() < 125);

	accessor.registerCustomEditor(int.class, "array.somePath", new CustomNumberEditor(Integer.class, false));
	sw.start("array3");
	for (int i = 0; i < 1000; i++) {
		accessor.setPropertyValue("array", input);
	}
	sw.stop();
	assertTrue("Took too long", sw.getLastTaskTimeMillis() < 100);

	accessor.registerCustomEditor(int.class, "array[0].somePath", new CustomNumberEditor(Integer.class, false));
	sw.start("array3");
	for (int i = 0; i < 1000; i++) {
		accessor.setPropertyValue("array", input);
	}
	sw.stop();
	assertTrue("Took too long", sw.getLastTaskTimeMillis() < 100);

	accessor.registerCustomEditor(int.class, new CustomNumberEditor(Integer.class, false));
	sw.start("array4");
	for (int i = 0; i < 100; i++) {
		accessor.setPropertyValue("array", input);
	}
	sw.stop();
	assertEquals(1024, target.getArray().length);
	assertEquals(0, target.getArray()[0]);
	assertTrue("Took too long", sw.getLastTaskTimeMillis() > time1);
}
 
Example 15
Source File: AbstractPropertyAccessorTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Test
public void setPrimitiveArrayPropertyLargeMatching() {
	Assume.group(TestGroup.PERFORMANCE);
	Assume.notLogging(LogFactory.getLog(AbstractPropertyAccessorTests.class));

	PrimitiveArrayBean target = new PrimitiveArrayBean();
	AbstractPropertyAccessor accessor = createAccessor(target);
	int[] input = new int[1024];
	StopWatch sw = new StopWatch();
	sw.start("array1");
	for (int i = 0; i < 1000; i++) {
		accessor.setPropertyValue("array", input);
	}
	sw.stop();
	assertEquals(1024, target.getArray().length);
	assertEquals(0, target.getArray()[0]);
	long time1 = sw.getLastTaskTimeMillis();
	assertTrue("Took too long", sw.getLastTaskTimeMillis() < 100);

	accessor.registerCustomEditor(String.class, new StringTrimmerEditor(false));
	sw.start("array2");
	for (int i = 0; i < 1000; i++) {
		accessor.setPropertyValue("array", input);
	}
	sw.stop();
	assertTrue("Took too long", sw.getLastTaskTimeMillis() < 125);

	accessor.registerCustomEditor(int.class, "array.somePath", new CustomNumberEditor(Integer.class, false));
	sw.start("array3");
	for (int i = 0; i < 1000; i++) {
		accessor.setPropertyValue("array", input);
	}
	sw.stop();
	assertTrue("Took too long", sw.getLastTaskTimeMillis() < 100);

	accessor.registerCustomEditor(int.class, "array[0].somePath", new CustomNumberEditor(Integer.class, false));
	sw.start("array3");
	for (int i = 0; i < 1000; i++) {
		accessor.setPropertyValue("array", input);
	}
	sw.stop();
	assertTrue("Took too long", sw.getLastTaskTimeMillis() < 100);

	accessor.registerCustomEditor(int.class, new CustomNumberEditor(Integer.class, false));
	sw.start("array4");
	for (int i = 0; i < 100; i++) {
		accessor.setPropertyValue("array", input);
	}
	sw.stop();
	assertEquals(1024, target.getArray().length);
	assertEquals(0, target.getArray()[0]);
	assertTrue("Took too long", sw.getLastTaskTimeMillis() > time1);
}
 
Example 16
Source File: AbstractPropertyAccessorTests.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Test
public void setPrimitiveArrayPropertyLargeMatching() {
	Assume.group(TestGroup.PERFORMANCE);
	Assume.notLogging(LogFactory.getLog(AbstractPropertyAccessorTests.class));

	PrimitiveArrayBean target = new PrimitiveArrayBean();
	AbstractPropertyAccessor accessor = createAccessor(target);
	int[] input = new int[1024];
	StopWatch sw = new StopWatch();
	sw.start("array1");
	for (int i = 0; i < 1000; i++) {
		accessor.setPropertyValue("array", input);
	}
	sw.stop();
	assertEquals(1024, target.getArray().length);
	assertEquals(0, target.getArray()[0]);
	long time1 = sw.getLastTaskTimeMillis();
	assertTrue("Took too long", sw.getLastTaskTimeMillis() < 100);

	accessor.registerCustomEditor(String.class, new StringTrimmerEditor(false));
	sw.start("array2");
	for (int i = 0; i < 1000; i++) {
		accessor.setPropertyValue("array", input);
	}
	sw.stop();
	assertTrue("Took too long", sw.getLastTaskTimeMillis() < 125);

	accessor.registerCustomEditor(int.class, "array.somePath", new CustomNumberEditor(Integer.class, false));
	sw.start("array3");
	for (int i = 0; i < 1000; i++) {
		accessor.setPropertyValue("array", input);
	}
	sw.stop();
	assertTrue("Took too long", sw.getLastTaskTimeMillis() < 100);

	accessor.registerCustomEditor(int.class, "array[0].somePath", new CustomNumberEditor(Integer.class, false));
	sw.start("array3");
	for (int i = 0; i < 1000; i++) {
		accessor.setPropertyValue("array", input);
	}
	sw.stop();
	assertTrue("Took too long", sw.getLastTaskTimeMillis() < 100);

	accessor.registerCustomEditor(int.class, new CustomNumberEditor(Integer.class, false));
	sw.start("array4");
	for (int i = 0; i < 100; i++) {
		accessor.setPropertyValue("array", input);
	}
	sw.stop();
	assertEquals(1024, target.getArray().length);
	assertEquals(0, target.getArray()[0]);
	assertTrue("Took too long", sw.getLastTaskTimeMillis() > time1);
}