Search in sources :

Example 1 with AllComponents

use of com.github.bordertech.wcomponents.AllComponents in project wcomponents by BorderTech.

the class WebXmlRenderingPerformance_Test method testRenderingScalingWithInterceptorChain.

@Test
public void testRenderingScalingWithInterceptorChain() throws Exception {
    final RenderContext renderContext = new WebXmlRenderContext(new PrintWriter(new NullWriter()));
    final AllComponents component1 = new AllComponents();
    makeAllInputsMandatory(component1);
    component1.setLocked(true);
    final UIContext uic1 = createUIContext();
    final UIContext uicChain = createUIContext();
    sendRequest(component1, uic1);
    Runnable runnable = new Runnable() {

        @Override
        public void run() {
            setActiveContext(uic1);
            for (int i = 0; i < NUM_REPETITIONS; i++) {
                // Just paint component
                component1.preparePaint(new MockRequest());
                component1.paint(renderContext);
            }
        }
    };
    // JIT warm-up
    runnable.run();
    long renderTime1 = time(runnable) / NUM_REPETITIONS;
    runnable = new Runnable() {

        @Override
        public void run() {
            setActiveContext(uicChain);
            for (int i = 0; i < NUM_REPETITIONS; i++) {
                // Paint with the interceptor chain
                WebUtilities.renderWithTransformToHTML(component1);
            }
        }
    };
    // JIT warm-up
    runnable.run();
    long renderTimeChain = time(runnable) / NUM_REPETITIONS;
    LOG.info("Render Component time: " + (renderTime1 / 1000000.0) + "ms");
    LOG.info("Render Component/Chain time: " + (renderTimeChain / 1000000.0) + "ms");
    Assert.assertTrue("Render with Chain time scaling should not be more than 3x.", renderTimeChain < renderTime1 * 3);
}
Also used : WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) RenderContext(com.github.bordertech.wcomponents.RenderContext) WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) UIContext(com.github.bordertech.wcomponents.UIContext) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) NullWriter(com.github.bordertech.wcomponents.util.NullWriter) PrintWriter(java.io.PrintWriter) AllComponents(com.github.bordertech.wcomponents.AllComponents) Test(org.junit.Test)

Example 2 with AllComponents

use of com.github.bordertech.wcomponents.AllComponents in project wcomponents by BorderTech.

the class WebXmlRenderingPerformance_Test method testRenderingScaling.

@Test
public void testRenderingScaling() throws Exception {
    final RenderContext renderContext = new WebXmlRenderContext(new PrintWriter(new NullWriter()));
    final AllComponents component1 = new AllComponents();
    final UIContext uic1 = createUIContext();
    sendRequest(component1, uic1);
    final AllComponents component10 = new AllComponents(10);
    final UIContext uic10 = createUIContext();
    sendRequest(component10, uic10);
    Runnable runnable = new Runnable() {

        @Override
        public void run() {
            setActiveContext(uic1);
            for (int i = 0; i < NUM_REPETITIONS; i++) {
                component1.paint(renderContext);
            }
        }
    };
    // JIT warm-up
    runnable.run();
    long renderTime1 = time(runnable) / NUM_REPETITIONS;
    runnable = new Runnable() {

        @Override
        public void run() {
            setActiveContext(uic10);
            for (int i = 0; i < NUM_REPETITIONS; i++) {
                component10.paint(renderContext);
            }
        }
    };
    // JIT warm-up
    runnable.run();
    long renderTime10 = time(runnable) / NUM_REPETITIONS;
    LOG.info("Render 1x time: " + (renderTime1 / 1000000.0) + "ms");
    LOG.info("Render 10x time: " + (renderTime10 / 1000000.0) + "ms");
    Assert.assertTrue("Render time scaling should be O(n)", renderTime10 < renderTime1 * 12);
}
Also used : WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) RenderContext(com.github.bordertech.wcomponents.RenderContext) WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) UIContext(com.github.bordertech.wcomponents.UIContext) NullWriter(com.github.bordertech.wcomponents.util.NullWriter) PrintWriter(java.io.PrintWriter) AllComponents(com.github.bordertech.wcomponents.AllComponents) Test(org.junit.Test)

Example 3 with AllComponents

use of com.github.bordertech.wcomponents.AllComponents in project wcomponents by BorderTech.

the class WebXmlRenderingPerformance_Test method testRenderingPerformance.

@Test
public void testRenderingPerformance() throws Exception {
    final AllComponents component = new AllComponents();
    final UIContext uic = createUIContext();
    sendRequest(component, uic);
    // Render and store the XML to compare against
    setActiveContext(uic);
    StringWriter tempStringWriter = new StringWriter();
    PrintWriter tempPrintWriter = new PrintWriter(tempStringWriter);
    component.paint(new WebXmlRenderContext(tempPrintWriter));
    tempPrintWriter.close();
    resetContext();
    // Run the test writing raw bytes to a writer - no computation necessary
    final byte[] xml = tempStringWriter.toString().getBytes("UTF-8");
    final CountingNullPrintWriter nullWriter = new CountingNullPrintWriter();
    LOG.info("Rendered UI size: " + xml.length + " bytes");
    Runnable runnable = new Runnable() {

        @Override
        public void run() {
            for (int i = 0; i < NUM_REPETITIONS; i++) {
                for (int j = 0; j < xml.length; j++) {
                    nullWriter.write(xml[j]);
                }
            }
        }
    };
    // JIT warm-up
    runnable.run();
    nullWriter.resetCount();
    long rawTime = time(runnable) / NUM_REPETITIONS;
    Assert.assertEquals("Incorrect amount of raw data written", xml.length * NUM_REPETITIONS, nullWriter.getCount());
    nullWriter.resetCount();
    // Run the test using WComponent rendering
    runnable = new Runnable() {

        @Override
        public void run() {
            setActiveContext(uic);
            for (int i = 0; i < NUM_REPETITIONS; i++) {
                component.paint(new WebXmlRenderContext(nullWriter));
            }
        }
    };
    // JIT warm-up
    runnable.run();
    nullWriter.resetCount();
    long renderTime = time(runnable) / NUM_REPETITIONS;
    Assert.assertEquals("Incorrect amount of rendered data written", xml.length * NUM_REPETITIONS, nullWriter.getCount());
    nullWriter.resetCount();
    LOG.info("Raw write time: " + (rawTime / 1000000.0) + "ms");
    LOG.info("WComponent render time: " + (renderTime / 1000000.0) + "ms");
    Assert.assertTrue("WComponent render time should not exceed 5x raw write time", renderTime < rawTime * 5);
}
Also used : WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) StringWriter(java.io.StringWriter) UIContext(com.github.bordertech.wcomponents.UIContext) AllComponents(com.github.bordertech.wcomponents.AllComponents) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Aggregations

AllComponents (com.github.bordertech.wcomponents.AllComponents)3 UIContext (com.github.bordertech.wcomponents.UIContext)3 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)3 PrintWriter (java.io.PrintWriter)3 Test (org.junit.Test)3 RenderContext (com.github.bordertech.wcomponents.RenderContext)2 NullWriter (com.github.bordertech.wcomponents.util.NullWriter)2 MockRequest (com.github.bordertech.wcomponents.util.mock.MockRequest)1 StringWriter (java.io.StringWriter)1