org.springframework.util.StopWatch.start()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(10.9k)|赞(0)|评价(0)|浏览(122)

本文整理了Java中org.springframework.util.StopWatch.start()方法的一些代码示例,展示了StopWatch.start()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StopWatch.start()方法的具体详情如下:
包路径:org.springframework.util.StopWatch
类名称:StopWatch
方法名:start

StopWatch.start介绍

[英]Start an unnamed task. The results are undefined if #stop()or timing methods are called without invoking this method.
[中]开始一项未命名的任务。如果在没有调用此方法的情况下调用#stop()或计时方法,则结果是未定义的。

代码示例

代码示例来源:origin: spring-projects/spring-framework

/**
 * Start an unnamed task. The results are undefined if {@link #stop()}
 * or timing methods are called without invoking this method.
 * @see #stop()
 */
public void start() throws IllegalStateException {
  start("");
}

代码示例来源:origin: spring-projects/spring-framework

@Override
protected Object invokeUnderTrace(MethodInvocation invocation, Log logger) throws Throwable {
  String name = createInvocationTraceName(invocation);
  StopWatch stopWatch = new StopWatch(name);
  stopWatch.start(name);
  try {
    return invocation.proceed();
  }
  finally {
    stopWatch.stop();
    writeToLog(logger, stopWatch.shortSummary());
  }
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void rejectsStartTwice() {
  sw.start("");
  sw.stop();
  sw.start("");
  assertTrue(sw.isRunning());
  exception.expect(IllegalStateException.class);
  sw.start("");
}

代码示例来源:origin: spring-projects/spring-framework

@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());
}

代码示例来源: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

@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 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

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();
}

代码示例来源:origin: spring-projects/spring-framework

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();
}

代码示例来源:origin: spring-projects/spring-framework

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();
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void testAspectsAndAdvisorAppliedToPrototypeIsFastEnough() {
  Assume.group(TestGroup.PERFORMANCE);
  Assume.notLogging(factoryLog);
  ClassPathXmlApplicationContext ac = newContext("aspectsPlusAdvisor.xml");
  StopWatch sw = new StopWatch();
  sw.start("Prototype Creation");
  for (int i = 0; i < 10000; i++) {
    ITestBean shouldBeWeaved = (ITestBean) ac.getBean("adrian2");
    if (i < 10) {
      doTestAspectsAndAdvisorAreApplied(ac, shouldBeWeaved);
    }
  }
  sw.stop();
  // What's a reasonable expectation for _any_ server or developer machine load?
  // 9 seconds?
  assertStopWatchTimeLimit(sw, 9000);
}

代码示例来源: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

/**
 * 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 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);
}

相关文章