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.

PerformanceTestLabelsAndOrderedLayouts.java 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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.AbstractOrderedLayout;
  20. import com.vaadin.ui.Button;
  21. import com.vaadin.ui.Button.ClickEvent;
  22. import com.vaadin.ui.Button.ClickListener;
  23. import com.vaadin.ui.CustomComponent;
  24. import com.vaadin.ui.Label;
  25. import com.vaadin.ui.VerticalLayout;
  26. public class PerformanceTestLabelsAndOrderedLayouts extends CustomComponent {
  27. private final AbstractOrderedLayout main;
  28. private final AbstractOrderedLayout testContainer;
  29. private Date startTime;
  30. private final Label result;
  31. private static final String DESCRIPTION = "Simple test that renders n labels into ordered layout.";
  32. private static final int INITIAL_COMPONENTS = 1000;
  33. public PerformanceTestLabelsAndOrderedLayouts() {
  34. main = new VerticalLayout();
  35. setCompositionRoot(main);
  36. addInfo();
  37. result = new Label();
  38. main.addComponent(result);
  39. main.addComponent(
  40. new Button("click when rendered", new ClickListener() {
  41. @Override
  42. public void buttonClick(ClickEvent event) {
  43. endTest();
  44. }
  45. }));
  46. main.addComponent(
  47. new Button("Click for layout repaint (cached components)",
  48. new ClickListener() {
  49. @Override
  50. public void buttonClick(ClickEvent event) {
  51. testContainer.markAsDirty();
  52. }
  53. }));
  54. testContainer = new VerticalLayout();
  55. for (int i = 0; i < INITIAL_COMPONENTS; i++) {
  56. Label l = new Label("foo" + i);
  57. testContainer.addComponent(l);
  58. }
  59. main.addComponent(testContainer);
  60. startTest();
  61. }
  62. public void startTest() {
  63. startTime = new Date();
  64. }
  65. public void endTest() {
  66. final long millis = (new Date()).getTime() - startTime.getTime();
  67. final Float f = new Float(millis / 1000.0);
  68. result.setValue("Test completed in " + f + " seconds");
  69. }
  70. private void addInfo() {
  71. main.addComponent(new Label(DESCRIPTION, ContentMode.HTML));
  72. }
  73. }