--- /dev/null
+/* *******************************************************************
+ * Copyright (c) 2003 Contributors.
+ * All rights reserved.
+ * This program and the accompanying materials are made available
+ * under the terms of the Common Public License v1.0
+ * which accompanies this distribution and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * Mik Kersten initial implementation
+ * ******************************************************************/
+
+package org.aspectj.ajde;
+
+/**
+ * @author Mik Kersten
+ */
+public class ModelPerformanceTest extends AjdeTestCase {
+
+ private final String CONFIG_FILE_PATH = "../examples/spacewar/spacewar/debug.lst";
+
+ public ModelPerformanceTest(String name) {
+ super(name);
+ }
+
+ public static void main(String[] args) {
+ junit.swingui.TestRunner.run(ModelPerformanceTest.class);
+ }
+
+ /**
+ * Assert that a compile that includes building the structure model
+ * adds an acceptable percentage of overhead.
+ *
+ * Does a few initial builds to minimize caching effects.
+ */
+ public void testRelativeToNoModel() {
+ timedBuild(true);
+ timedBuild(false);
+ timedBuild(true);
+
+ long rawBuildTime = timedBuild(false);
+ long modelBuildTime = timedBuild(true);
+ float overhead = (float)modelBuildTime / (float)rawBuildTime;
+
+ assertTrue(overhead < 1.3);
+// System.err.println("> overhead: " + overhead);
+ }
+
+ public long timedBuild(boolean buildModel) {
+ long startTime = System.currentTimeMillis();
+ doSynchronousBuild(CONFIG_FILE_PATH);
+ Ajde.getDefault().getBuildManager().setBuildModelMode(buildModel);
+ long endTime = System.currentTimeMillis();
+ return (endTime - startTime);
+
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp("examples");
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+}
+
public void testFileNodeFind() throws IOException {
File testFile = openFile("figures-coverage/figures/Main.java");
+
+// System.err.println(((IProgramElement)((IProgramElement)Ajde.getDefault().getStructureModelManager().getHierarchy().getRoot().getChildren().get(0)).getChildren().get(3)).getSourceLocation().getSourceFile().getAbsolutePath());
+// System.err.println(testFile.getAbsolutePath());
+
IProgramElement node = Ajde.getDefault().getStructureModelManager().getHierarchy().findElementForSourceLine(
- testFile.getCanonicalPath(), 1);
+ testFile.getAbsolutePath(), 1);
assertTrue("find result", node != null) ;
assertEquals("find result has children", 3, node.getChildren().size()) ;
IProgramElement pNode = (IProgramElement)node;
assertTrue("model exists", model != null);
assertTrue("root exists", model.getRoot() != null);
File testFile = openFile("figures-coverage/figures/Main.java");
- IProgramElement node = model.findElementForSourceLine(testFile.getCanonicalPath(), 11);
+ IProgramElement node = model.findElementForSourceLine(testFile.getAbsolutePath(), 11);
assertTrue("find result", node != null);
IProgramElement pNode = (IProgramElement)((IProgramElement)node).getParent();
if (null == pNode) {