Search in sources :

Example 71 with StopWatch

use of org.springframework.util.StopWatch in project spring-framework by spring-projects.

the class DefaultListableBeanFactoryTests method testPrototypeCreationWithResolvedConstructorArgumentsIsFastEnough.

@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));
    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);
}
Also used : ITestBean(org.springframework.tests.sample.beans.ITestBean) DerivedTestBean(org.springframework.tests.sample.beans.DerivedTestBean) TestBean(org.springframework.tests.sample.beans.TestBean) NestedTestBean(org.springframework.tests.sample.beans.NestedTestBean) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference) StopWatch(org.springframework.util.StopWatch) Test(org.junit.Test)

Example 72 with StopWatch

use of org.springframework.util.StopWatch in project spring-framework by spring-projects.

the class DefaultListableBeanFactoryTests method testPrototypeCreationWithPropertiesIsFastEnough.

@Test
public void testPrototypeCreationWithPropertiesIsFastEnough() {
    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("name", "juergen");
    rbd.getPropertyValues().add("age", "99");
    lbf.registerBeanDefinition("test", rbd);
    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);
}
Also used : ITestBean(org.springframework.tests.sample.beans.ITestBean) DerivedTestBean(org.springframework.tests.sample.beans.DerivedTestBean) TestBean(org.springframework.tests.sample.beans.TestBean) NestedTestBean(org.springframework.tests.sample.beans.NestedTestBean) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) StopWatch(org.springframework.util.StopWatch) Test(org.junit.Test)

Example 73 with StopWatch

use of org.springframework.util.StopWatch in project spring-framework by spring-projects.

the class MapAccessTests method testGetValuePerformance.

@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));
}
Also used : StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) HashMap(java.util.HashMap) Expression(org.springframework.expression.Expression) ExpressionParser(org.springframework.expression.ExpressionParser) SpelExpressionParser(org.springframework.expression.spel.standard.SpelExpressionParser) EvaluationContext(org.springframework.expression.EvaluationContext) StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) StopWatch(org.springframework.util.StopWatch) Test(org.junit.Test)

Example 74 with StopWatch

use of org.springframework.util.StopWatch in project spring-boot by spring-projects.

the class MetricsFilter method createStopWatchIfNecessary.

private StopWatch createStopWatchIfNecessary(HttpServletRequest request) {
    StopWatch stopWatch = (StopWatch) request.getAttribute(ATTRIBUTE_STOP_WATCH);
    if (stopWatch == null) {
        stopWatch = new StopWatch();
        stopWatch.start();
        request.setAttribute(ATTRIBUTE_STOP_WATCH, stopWatch);
    }
    return stopWatch;
}
Also used : StopWatch(org.springframework.util.StopWatch)

Example 75 with StopWatch

use of org.springframework.util.StopWatch in project pinpoint by naver.

the class LegacyAgentStatController method getAgentStatV2.

@Deprecated
@PreAuthorize("hasPermission(new com.navercorp.pinpoint.web.vo.AgentParam(#agentId, #to), 'agentParam', 'inspector')")
@RequestMapping(value = "/getAgentStat/v2", method = RequestMethod.GET)
@ResponseBody
public LegacyAgentStatChartGroup getAgentStatV2(@RequestParam("agentId") String agentId, @RequestParam("from") long from, @RequestParam("to") long to, @RequestParam(value = "sampleRate", required = false) Integer sampleRate) throws Exception {
    StopWatch watch = new StopWatch();
    watch.start("agentStatService.selectAgentStatList");
    TimeWindow timeWindow = new TimeWindow(new Range(from, to), new TimeWindowSlotCentricSampler());
    LegacyAgentStatChartGroup chartGroup = this.v2Service.selectAgentStatList(agentId, timeWindow);
    watch.stop();
    if (logger.isInfoEnabled()) {
        logger.info("getAgentStatV2(agentId={}, from={}, to={}) : {}ms", agentId, from, to, watch.getLastTaskTimeMillis());
    }
    return chartGroup;
}
Also used : LegacyAgentStatChartGroup(com.navercorp.pinpoint.web.vo.stat.chart.LegacyAgentStatChartGroup) Range(com.navercorp.pinpoint.web.vo.Range) TimeWindow(com.navercorp.pinpoint.web.util.TimeWindow) StopWatch(org.springframework.util.StopWatch) TimeWindowSlotCentricSampler(com.navercorp.pinpoint.web.util.TimeWindowSlotCentricSampler) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

StopWatch (org.springframework.util.StopWatch)112 Test (org.junit.Test)44 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)12 ArrayList (java.util.ArrayList)9 Test (org.junit.jupiter.api.Test)9 ITestBean (org.springframework.tests.sample.beans.ITestBean)9 TestBean (org.springframework.tests.sample.beans.TestBean)9 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)8 List (java.util.List)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 ITestBean (org.springframework.beans.testfixture.beans.ITestBean)6 MockHttpServletRequest (org.springframework.mock.web.test.MockHttpServletRequest)6 ApplicationMap (com.navercorp.pinpoint.web.applicationmap.ApplicationMap)5 Ignore (org.junit.Ignore)5 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)5 NestedTestBean (org.springframework.tests.sample.beans.NestedTestBean)5 Range (com.navercorp.pinpoint.web.vo.Range)4 Dataset (org.apache.jena.query.Dataset)4