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 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * Copyright 2000-2016 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.tests;
  17. import java.util.Date;
  18. import com.vaadin.shared.ui.ContentMode;
  19. import com.vaadin.ui.Button;
  20. import com.vaadin.ui.Button.ClickEvent;
  21. import com.vaadin.ui.CustomComponent;
  22. import com.vaadin.ui.Label;
  23. import com.vaadin.ui.VerticalLayout;
  24. import com.vaadin.v7.ui.Table;
  25. public class PerformanceTestSubTreeCaching extends CustomComponent {
  26. private final VerticalLayout main;
  27. private final VerticalLayout testContainer;
  28. private Date startTime;
  29. private final Label result;
  30. private static final String DESCRIPTION = "Hypothesis: Toolkit 4 has major architechtural problem when adding "
  31. + "small incrementall updates to a container which has either a lot or "
  32. + "some very slow components in it. Toolkit 5 has 'subtree caching' and a"
  33. + " small amount of logic in containers, so CommunicationManager can assure"
  34. + " that client do not need information about unchanged components it contains."
  35. + " Completing test ought to be much faster with Toolkit 5.";
  36. private static final int INITIAL_COMPONENTS = 40;
  37. public PerformanceTestSubTreeCaching() {
  38. main = new VerticalLayout();
  39. setCompositionRoot(main);
  40. addInfo();
  41. Button b = new Button("start test", new Button.ClickListener() {
  42. @Override
  43. public void buttonClick(ClickEvent event) {
  44. startTest();
  45. }
  46. });
  47. b.setDescription(
  48. "Push this button to start test. A test label will be rendered above existing components.");
  49. main.addComponent(b);
  50. b = new Button("end test", new Button.ClickListener() {
  51. @Override
  52. public void buttonClick(ClickEvent event) {
  53. endTest();
  54. }
  55. });
  56. b.setDescription(
  57. "Push this button as soon as test componenet is rendered.");
  58. main.addComponent(b);
  59. result = new Label();
  60. main.addComponent(result);
  61. testContainer = new VerticalLayout();
  62. populateContainer(testContainer, INITIAL_COMPONENTS);
  63. main.addComponent(testContainer);
  64. }
  65. public void startTest() {
  66. startTime = new Date();
  67. testContainer.addComponentAsFirst(new Label("Simplel Test Component"));
  68. }
  69. public void endTest() {
  70. final long millis = (new Date()).getTime() - startTime.getTime();
  71. final Float f = new Float(millis / 1000.0);
  72. result.setValue("Test completed in " + f + " seconds");
  73. }
  74. /**
  75. * Adds n Table components to given container
  76. *
  77. * @param testContainer2
  78. */
  79. private void populateContainer(VerticalLayout container, int n) {
  80. for (int i = 0; i < n; i++) {
  81. // array_type array_element = [i];
  82. final Table t = TestForTablesInitialColumnWidthLogicRendering
  83. .getTestTable(5, 100);
  84. container.addComponent(t);
  85. }
  86. }
  87. private void addInfo() {
  88. main.addComponent(new Label(DESCRIPTION, ContentMode.HTML));
  89. }
  90. }