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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * Copyright 2000-2013 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.label.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.Table;
  24. import com.vaadin.ui.VerticalLayout;
  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("Push this button to start test. A test label will be rendered above existing components.");
  48. main.addComponent(b);
  49. b = new Button("end test", new Button.ClickListener() {
  50. @Override
  51. public void buttonClick(ClickEvent event) {
  52. endTest();
  53. }
  54. });
  55. b.setDescription("Push this button as soon as test componenet is rendered.");
  56. main.addComponent(b);
  57. result = new Label();
  58. main.addComponent(result);
  59. testContainer = new VerticalLayout();
  60. populateContainer(testContainer, INITIAL_COMPONENTS);
  61. main.addComponent(testContainer);
  62. }
  63. public void startTest() {
  64. startTime = new Date();
  65. testContainer.addComponentAsFirst(new Label("Simplel Test Component"));
  66. }
  67. public void endTest() {
  68. final long millis = (new Date()).getTime() - startTime.getTime();
  69. final Float f = new Float(millis / 1000.0);
  70. result.setValue("Test completed in " + f + " seconds");
  71. }
  72. /**
  73. * Adds n Table components to given container
  74. *
  75. * @param testContainer2
  76. */
  77. private void populateContainer(VerticalLayout container, int n) {
  78. for (int i = 0; i < n; i++) {
  79. // array_type array_element = [i];
  80. final Table t = TestForTablesInitialColumnWidthLogicRendering
  81. .getTestTable(5, 100);
  82. container.addComponent(t);
  83. }
  84. }
  85. private void addInfo() {
  86. main.addComponent(new Label(DESCRIPTION, ContentMode.HTML));
  87. }
  88. }