From b677bb47325aae5c70afb3910116b3fe92f54f22 Mon Sep 17 00:00:00 2001 From: Stefan Xenos Date: Sun, 28 Feb 2016 20:02:07 -0800 Subject: Bug 489963 - Improve the performance of the Region class Change-Id: I216564c15fd293432051ec8434027400aadec29c Signed-off-by: Stefan Xenos --- .../tests/performance/AllPerformanceTests.java | 1 + .../tests/performance/RegionPerformanceTests.java | 102 +++++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 org.eclipse.jdt.core.tests.performance/src/org/eclipse/jdt/core/tests/performance/RegionPerformanceTests.java (limited to 'org.eclipse.jdt.core.tests.performance/src') diff --git a/org.eclipse.jdt.core.tests.performance/src/org/eclipse/jdt/core/tests/performance/AllPerformanceTests.java b/org.eclipse.jdt.core.tests.performance/src/org/eclipse/jdt/core/tests/performance/AllPerformanceTests.java index a5417e4b64..18a41e942a 100644 --- a/org.eclipse.jdt.core.tests.performance/src/org/eclipse/jdt/core/tests/performance/AllPerformanceTests.java +++ b/org.eclipse.jdt.core.tests.performance/src/org/eclipse/jdt/core/tests/performance/AllPerformanceTests.java @@ -40,6 +40,7 @@ public class AllPerformanceTests extends junit.framework.TestCase { FullSourceWorkspaceModelTests.class, FullSourceWorkspaceCompletionTests.class, FullSourceWorkspaceFormatterTests.class, + RegionPerformanceTests.class }; } diff --git a/org.eclipse.jdt.core.tests.performance/src/org/eclipse/jdt/core/tests/performance/RegionPerformanceTests.java b/org.eclipse.jdt.core.tests.performance/src/org/eclipse/jdt/core/tests/performance/RegionPerformanceTests.java new file mode 100644 index 0000000000..9dbedb3f85 --- /dev/null +++ b/org.eclipse.jdt.core.tests.performance/src/org/eclipse/jdt/core/tests/performance/RegionPerformanceTests.java @@ -0,0 +1,102 @@ +/******************************************************************************* + * Copyright (c) 2015 Google, Inc and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Stefan Xenos (Google) - Initial implementation + *******************************************************************************/ +package org.eclipse.jdt.core.tests.performance; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.IPath; +import org.eclipse.jdt.core.IJavaElement; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.IPackageFragment; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.tests.builder.TestingEnvironment; +import org.eclipse.jdt.core.tests.junit.extension.TestCase; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.internal.core.Region; + +import junit.framework.Test; +import junit.framework.TestSuite; + +public class RegionPerformanceTests extends TestCase { + + // Log file streams + protected IProject project; + private TestingEnvironment env = null; + + public RegionPerformanceTests(String name) { + super(name); + } + + public static Test suite() { + return new TestSuite(RegionPerformanceTests.class); + } + + protected IJavaProject createJavaProject(final String projectName) throws Exception { + IPath projectPath = this.env.addProject(projectName, "1.8"); + this.env.addExternalJars(projectPath, Util.getJavaClassLibs()); + // remove old package fragment root so that names don't collide + this.env.removePackageFragmentRoot(projectPath, ""); + this.env.addPackageFragmentRoot(projectPath, "src"); + this.env.setOutputFolder(projectPath, "bin"); + final IJavaProject javaProj = this.env.getJavaProject(projectPath); + return javaProj; + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + + if (this.env == null) { + this.env = new TestingEnvironment(); + this.env.openEmptyWorkspace(); + } + this.env.resetWorkspace(); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + + this.env.resetWorkspace(); + JavaCore.setOptions(JavaCore.getDefaultOptions()); + } + + public void testRegion() throws Exception { + IJavaProject jproj = createJavaProject("RegionTest"); + IProject proj = jproj.getProject(); + IPath projPath = proj.getFullPath(); + IPath root = projPath.append("src"); + + for (int idx = 0; idx < 1000; idx++) { + this.env.addClass(root, "test", "Foo" + idx, "package test;\n\n" + "public class Foo" + idx + " {\n" + "}"); + } + + this.env.fullBuild(); + + for (int idx = 0; idx < 10; idx++) { + startMeasuring(); + Region region = new Region(); + IPackageFragment[] fragments = jproj.getPackageFragments(); + + for (IPackageFragment next : fragments) { + IJavaElement[] children = next.getChildren(); + + for (IJavaElement nextChild : children) { + region.add(nextChild); + } + } + stopMeasuring(); + } + + // Commit + commitMeasurements(); + assertPerformance(); + } +} -- cgit v1.2.3