001: /*******************************************************************************
002: * Copyright (c) 2005, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jface.tests.performance;
011:
012: import java.util.ArrayList;
013: import java.util.Collection;
014:
015: import org.eclipse.core.runtime.CoreException;
016: import org.eclipse.test.performance.Dimension;
017: import org.eclipse.ui.tests.performance.TestRunnable;
018:
019: public class FastTreeTest extends TreeTest {
020:
021: public FastTreeTest(String testName, int tagging) {
022: super (testName, tagging);
023: }
024:
025: public FastTreeTest(String testName) {
026: super (testName);
027: }
028:
029: /**
030: * @throws CoreException
031: * Test addition to the tree one element at a time.
032: */
033: public void testAddTenTenTimes() throws CoreException {
034:
035: doTestAdd(10, TEST_COUNT, false);
036: }
037:
038: /**
039: * @throws CoreException
040: * Test addition to the tree one element at a time.
041: */
042: public void testAddFiftyTenTimes() throws CoreException {
043:
044: doTestAdd(50, TEST_COUNT, false);
045: }
046:
047: /**
048: * @throws CoreException
049: * Test addition to the tree one element at a time.
050: */
051: public void testAddHundredTenTimes() throws CoreException {
052:
053: tagIfNecessary(
054: "JFace - Add 10000 items 100 at a time TreeViewer 10 times",
055: Dimension.ELAPSED_PROCESS);
056:
057: doTestAdd(100, TEST_COUNT, false);
058: }
059:
060: /**
061: * Run the test for one of the fast insertions.
062: *
063: * @param count
064: * @throws CoreException
065: */
066: protected void doTestAdd(final int increment, final int total,
067: final boolean preSort) throws CoreException {
068:
069: openBrowser();
070:
071: exercise(new TestRunnable() {
072: public void run() {
073:
074: TestTreeElement input = new TestTreeElement(0, null);
075: viewer.setInput(input);
076: input.createChildren(total);
077: if (preSort)
078: viewer.getSorter().sort(viewer, input.children);
079: Collection batches = new ArrayList();
080: int blocks = input.children.length / increment;
081: for (int j = 0; j < blocks; j = j + increment) {
082: Object[] batch = new Object[increment];
083: System.arraycopy(input.children, j * increment,
084: batch, 0, increment);
085: batches.add(batch);
086: }
087: processEvents();
088: Object[] batchArray = batches.toArray();
089: startMeasuring();
090: for (int i = 0; i < 10; i++) {
091: viewer.remove(input.children);
092: for (int k = 0; k < batchArray.length; k++) {
093: viewer.add(input, (Object[]) batchArray[k]);
094: processEvents();
095: }
096: }
097:
098: stopMeasuring();
099:
100: }
101: }, MIN_ITERATIONS, ITERATIONS, JFacePerformanceSuite.MAX_TIME);
102:
103: commitMeasurements();
104: assertPerformance();
105:
106: }
107: }
|