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