本文整理了Java中org.springframework.util.StopWatch.getTotalTimeMillis()
方法的一些代码示例,展示了StopWatch.getTotalTimeMillis()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StopWatch.getTotalTimeMillis()
方法的具体详情如下:
包路径:org.springframework.util.StopWatch
类名称:StopWatch
方法名:getTotalTimeMillis
[英]Return the total time in milliseconds for all tasks.
[中]返回所有任务的总时间(以毫秒为单位)。
代码示例来源:origin: spring-projects/spring-framework
/**
* Return a short description of the total running time.
*/
public String shortSummary() {
return "StopWatch '" + getId() + "': running time (millis) = " + getTotalTimeMillis();
}
代码示例来源:origin: spring-projects/spring-framework
@Test // SPR-6354
public void destroyLazyInitSchedulerWithCustomShutdownOrderDoesNotHang() {
ConfigurableApplicationContext context =
new ClassPathXmlApplicationContext("quartzSchedulerLifecycleTests.xml", getClass());
assertNotNull(context.getBean("lazyInitSchedulerWithCustomShutdownOrder"));
StopWatch sw = new StopWatch();
sw.start("lazyScheduler");
context.close();
sw.stop();
assertTrue("Quartz Scheduler with lazy-init is hanging on destruction: " +
sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 500);
}
代码示例来源:origin: spring-projects/spring-framework
private void assertStopWatchTimeLimit(final StopWatch sw, final long maxTimeMillis) {
long totalTimeMillis = sw.getTotalTimeMillis();
assertTrue("'" + sw.getLastTaskName() + "' took too long: expected less than<" + maxTimeMillis +
"> ms, actual<" + totalTimeMillis + "> ms.", totalTimeMillis < maxTimeMillis);
}
代码示例来源:origin: spring-projects/spring-framework
@Test // SPR-6354
public void destroyLazyInitSchedulerWithDefaultShutdownOrderDoesNotHang() {
ConfigurableApplicationContext context =
new ClassPathXmlApplicationContext("quartzSchedulerLifecycleTests.xml", getClass());
assertNotNull(context.getBean("lazyInitSchedulerWithDefaultShutdownOrder"));
StopWatch sw = new StopWatch();
sw.start("lazyScheduler");
context.close();
sw.stop();
assertTrue("Quartz Scheduler with lazy-init is hanging on destruction: " +
sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 500);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testGetIntParameterWithDefaultValueHandlingIsFastEnough() {
Assume.group(TestGroup.PERFORMANCE);
MockHttpServletRequest request = new MockHttpServletRequest();
StopWatch sw = new StopWatch();
sw.start();
for (int i = 0; i < 1000000; i++) {
ServletRequestUtils.getIntParameter(request, "nonExistingParam", 0);
}
sw.stop();
System.out.println(sw.getTotalTimeMillis());
assertTrue("getStringParameter took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 250);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testGetStringParameterWithDefaultValueHandlingIsFastEnough() {
Assume.group(TestGroup.PERFORMANCE);
MockHttpServletRequest request = new MockHttpServletRequest();
StopWatch sw = new StopWatch();
sw.start();
for (int i = 0; i < 1000000; i++) {
ServletRequestUtils.getStringParameter(request, "nonExistingParam", "defaultValue");
}
sw.stop();
System.out.println(sw.getTotalTimeMillis());
assertTrue("getStringParameter took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 250);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testGetDoubleParameterWithDefaultValueHandlingIsFastEnough() {
Assume.group(TestGroup.PERFORMANCE);
MockHttpServletRequest request = new MockHttpServletRequest();
StopWatch sw = new StopWatch();
sw.start();
for (int i = 0; i < 1000000; i++) {
ServletRequestUtils.getDoubleParameter(request, "nonExistingParam", 0d);
}
sw.stop();
System.out.println(sw.getTotalTimeMillis());
assertTrue("getStringParameter took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 250);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testGetLongParameterWithDefaultValueHandlingIsFastEnough() {
Assume.group(TestGroup.PERFORMANCE);
MockHttpServletRequest request = new MockHttpServletRequest();
StopWatch sw = new StopWatch();
sw.start();
for (int i = 0; i < 1000000; i++) {
ServletRequestUtils.getLongParameter(request, "nonExistingParam", 0);
}
sw.stop();
System.out.println(sw.getTotalTimeMillis());
assertTrue("getStringParameter took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 250);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testGetFloatParameterWithDefaultValueHandlingIsFastEnough() {
Assume.group(TestGroup.PERFORMANCE);
MockHttpServletRequest request = new MockHttpServletRequest();
StopWatch sw = new StopWatch();
sw.start();
for (int i = 0; i < 1000000; i++) {
ServletRequestUtils.getFloatParameter(request, "nonExistingParam", 0f);
}
sw.stop();
System.out.println(sw.getTotalTimeMillis());
assertTrue("getStringParameter took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 250);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testGetBooleanParameterWithDefaultValueHandlingIsFastEnough() {
Assume.group(TestGroup.PERFORMANCE);
MockHttpServletRequest request = new MockHttpServletRequest();
StopWatch sw = new StopWatch();
sw.start();
for (int i = 0; i < 1000000; i++) {
ServletRequestUtils.getBooleanParameter(request, "nonExistingParam", false);
}
sw.stop();
System.out.println(sw.getTotalTimeMillis());
assertTrue("getStringParameter took too long: " + sw.getTotalTimeMillis(), sw.getTotalTimeMillis() < 250);
}
代码示例来源:origin: spring-projects/spring-framework
@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));
}
代码示例来源:origin: spring-projects/spring-framework
@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);
}
代码示例来源:origin: spring-projects/spring-framework
@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);
}
代码示例来源:origin: spring-projects/spring-framework
@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);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void testPrototypeCreationWithOverriddenResourcePropertiesIsFastEnough() {
GenericApplicationContext ctx = new GenericApplicationContext();
AnnotationConfigUtils.registerAnnotationConfigProcessors(ctx);
ctx.refresh();
RootBeanDefinition rbd = new RootBeanDefinition(ResourceAnnotatedTestBean.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() < 4000);
}
代码示例来源:origin: spring-projects/spring-framework
@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);
}
代码示例来源:origin: spring-projects/spring-framework
@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);
}
代码示例来源:origin: spring-projects/spring-framework
@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);
}
代码示例来源:origin: spring-projects/spring-framework
/**
* This is primarily a test for the efficiency of our
* usage of CGLIB. If we create too many classes with
* CGLIB this will be slow or will run out of memory.
*/
@Test
public void testManyProxies() {
Assume.group(TestGroup.PERFORMANCE);
int howMany = 10000;
StopWatch sw = new StopWatch();
sw.start("Create " + howMany + " proxies");
testManyProxies(howMany);
sw.stop();
assertTrue("Proxy creation was too slow", sw.getTotalTimeMillis() < 5000);
}
代码示例来源:origin: spring-projects/spring-framework
@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);
}
内容来源于网络,如有侵权,请联系作者删除!