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

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