You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PerformanceTestSubTreeCaching.java 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. @ITMillApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.tests;
  5. import java.util.Date;
  6. import com.vaadin.ui.Button;
  7. import com.vaadin.ui.CustomComponent;
  8. import com.vaadin.ui.Label;
  9. import com.vaadin.ui.OrderedLayout;
  10. import com.vaadin.ui.Table;
  11. public class PerformanceTestSubTreeCaching extends CustomComponent {
  12. private final OrderedLayout main;
  13. private final OrderedLayout testContainer;
  14. private Date startTime;
  15. private final Label result;
  16. private static final String DESCRIPTION = "Hypothesis: Toolkit 4 has major architechtural problem when adding "
  17. + "small incrementall updates to a container which has either a lot or "
  18. + "some very slow components in it. Toolkit 5 has 'subtree caching' and a"
  19. + " small amount of logic in containers, so CommunicationManager can assure"
  20. + " that client do not need information about unchanged components it contains."
  21. + " Completing test ought to be much faster with Toolkit 5.";
  22. private static final int INITIAL_COMPONENTS = 40;
  23. public PerformanceTestSubTreeCaching() {
  24. main = new OrderedLayout();
  25. setCompositionRoot(main);
  26. addInfo();
  27. Button b = new Button("start test", this, "startTest");
  28. b
  29. .setDescription("Push this button to start test. A test label will be rendered above existing components.");
  30. main.addComponent(b);
  31. b = new Button("end test", this, "endTest");
  32. b
  33. .setDescription("Push this button as soon as test componenet is rendered.");
  34. main.addComponent(b);
  35. result = new Label();
  36. main.addComponent(result);
  37. testContainer = new OrderedLayout();
  38. populateContainer(testContainer, INITIAL_COMPONENTS);
  39. main.addComponent(testContainer);
  40. }
  41. public void startTest() {
  42. startTime = new Date();
  43. testContainer.addComponentAsFirst(new Label("Simplel Test Component"));
  44. }
  45. public void endTest() {
  46. final long millis = (new Date()).getTime() - startTime.getTime();
  47. final Float f = new Float(millis / 1000.0);
  48. result.setValue("Test completed in " + f + " seconds");
  49. }
  50. /**
  51. * Adds n Table components to given container
  52. *
  53. * @param testContainer2
  54. */
  55. private void populateContainer(OrderedLayout container, int n) {
  56. for (int i = 0; i < n; i++) {
  57. // array_type array_element = [i];
  58. final Table t = TestForTablesInitialColumnWidthLogicRendering
  59. .getTestTable(5, 100);
  60. container.addComponent(t);
  61. }
  62. }
  63. private void addInfo() {
  64. main.addComponent(new Label(DESCRIPTION, Label.CONTENT_XHTML));
  65. }
  66. }