Search in sources :

Example 61 with StopWatch

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

the class AnnotationProcessorPerformanceTests method testPrototypeCreationWithAutowiredPropertiesIsFastEnough.

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

Example 62 with StopWatch

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

the class DefaultConversionServiceTests method testPerformance1.

@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++) {
        new Integer(3).toString();
    }
    watch.stop();
// System.out.println(watch.prettyPrint());
}
Also used : BigInteger(java.math.BigInteger) StopWatch(org.springframework.util.StopWatch) Test(org.junit.Test)

Example 63 with StopWatch

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

the class GenericConversionServiceTests method testPerformance2.

@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());
}
Also used : TypeDescriptor(org.springframework.core.convert.TypeDescriptor) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) StopWatch(org.springframework.util.StopWatch) Test(org.junit.Test)

Example 64 with StopWatch

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

the class GenericConversionServiceTests method testPerformance3.

@Test
public void testPerformance3() throws Exception {
    Assume.group(TestGroup.PERFORMANCE);
    StopWatch watch = new StopWatch("map<string, string> -> map<string, integer> conversionPerformance");
    watch.start("convert 4,000,000 with conversion service");
    Map<String, String> source = new HashMap<>();
    source.put("1", "1");
    source.put("2", "2");
    source.put("3", "3");
    TypeDescriptor td = new TypeDescriptor(getClass().getField("map"));
    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++) {
        Map<String, Integer> target = new HashMap<>(source.size());
        for (Map.Entry<String, String> entry : source.entrySet()) {
            target.put(entry.getKey(), Integer.valueOf(entry.getValue()));
        }
    }
    watch.stop();
// System.out.println(watch.prettyPrint());
}
Also used : TypeDescriptor(org.springframework.core.convert.TypeDescriptor) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) StopWatch(org.springframework.util.StopWatch) Test(org.junit.Test)

Example 65 with StopWatch

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

the class FilteredMapServiceImpl method selectApplicationMap.

/**
     * filtered application map
     */
@Override
public ApplicationMap selectApplicationMap(List<TransactionId> transactionIdList, Range originalRange, Range scanRange, Filter filter) {
    if (transactionIdList == null) {
        throw new NullPointerException("transactionIdList must not be null");
    }
    if (filter == null) {
        throw new NullPointerException("filter must not be null");
    }
    StopWatch watch = new StopWatch();
    watch.start();
    final List<List<SpanBo>> filterList = selectFilteredSpan(transactionIdList, filter);
    DotExtractor dotExtractor = createDotExtractor(scanRange, filterList);
    ApplicationMap map = createMap(originalRange, scanRange, filterList);
    ApplicationMapWithScatterScanResult applicationMapWithScatterScanResult = new ApplicationMapWithScatterScanResult(map, dotExtractor.getApplicationScatterScanResult());
    watch.stop();
    logger.debug("Select filtered application map elapsed. {}ms", watch.getTotalTimeMillis());
    return applicationMapWithScatterScanResult;
}
Also used : ApplicationMap(com.navercorp.pinpoint.web.applicationmap.ApplicationMap) ApplicationMapWithScatterScanResult(com.navercorp.pinpoint.web.applicationmap.ApplicationMapWithScatterScanResult) ArrayList(java.util.ArrayList) List(java.util.List) StopWatch(org.springframework.util.StopWatch)

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