예제 #1
0
  public void loadDictionaryTest(@NotNull final String name, int wordCount) throws IOException {
    final Transformation transform = new Transformation();
    PlatformTestUtil.startPerformanceTest(
            "load dictionary",
            times.get(name),
            new ThrowableRunnable() {
              @Override
              public void run() throws Exception {
                dictionary =
                    CompressedDictionary.create(
                        new StreamLoader(
                            DefaultBundledDictionariesProvider.class.getResourceAsStream(name),
                            name),
                        transform);
              }
            })
        .cpuBound()
        .assertTiming();

    final Set<String> wordsToStoreAndCheck = createWordSets(name, 50000, 1).getFirst();
    PlatformTestUtil.startPerformanceTest(
            "words contain",
            2000,
            new ThrowableRunnable() {
              @Override
              public void run() throws Exception {
                for (String s : wordsToStoreAndCheck) {
                  assertTrue(dictionary.contains(s));
                }
              }
            })
        .cpuBound()
        .assertTiming();
  }
  public void testToStringOnUnqualified() {
    final PsiFile file =
        myFixture.addFileToProject(
            "Foo.java",
            "public class Fix {\n"
                + "    {\n"
                + "        <caret>toString();\n"
                + "    }\n"
                + "}\n"
                + "class FixImpl1 extends Fix {\n"
                + "    @Override\n"
                + "    public String toString() {\n"
                + "        return \"Impl1\";\n"
                + "    }\n"
                + "}\n"
                + "class FixImpl2 extends Fix {\n"
                + "    @Override\n"
                + "    public String toString() {\n"
                + "        return \"Impl2\";\n"
                + "    }\n"
                + "}");
    myFixture.configureFromExistingVirtualFile(file.getVirtualFile());

    PlatformTestUtil.startPerformanceTest(
            getTestName(false),
            150,
            () -> {
              PsiElement[] impls = getTargets(file);
              assertEquals(3, impls.length);
            })
        .cpuBound()
        .usesAllCPUCores()
        .assertTiming();
  }
  public void testRangeHighlighterLinesInRangeForLongLinePerformance() throws Exception {
    final int N = 50000;
    Document document =
        EditorFactory.getInstance().createDocument(StringUtil.repeatSymbol('x', 2 * N));

    final MarkupModelEx markupModel =
        (MarkupModelEx) DocumentMarkupModel.forDocument(document, ourProject, true);
    for (int i = 0; i < N - 1; i++) {
      markupModel.addRangeHighlighter(2 * i, 2 * i + 1, 0, null, HighlighterTargetArea.EXACT_RANGE);
    }
    markupModel.addRangeHighlighter(
        N / 2, N / 2 + 1, 0, null, HighlighterTargetArea.LINES_IN_RANGE);

    PlatformTestUtil.startPerformanceTest(
            "slow highlighters lookup",
            (int) (N * Math.log(N) / 1000),
            new ThrowableRunnable() {
              @Override
              public void run() {
                List<RangeHighlighterEx> list = new ArrayList<RangeHighlighterEx>();
                CommonProcessors.CollectProcessor<RangeHighlighterEx> coll =
                    new CommonProcessors.CollectProcessor<RangeHighlighterEx>(list);
                for (int i = 0; i < N - 1; i++) {
                  list.clear();
                  markupModel.processRangeHighlightersOverlappingWith(2 * i, 2 * i + 1, coll);
                  assertEquals(2, list.size()); // 1 line plus one exact range marker
                }
              }
            })
        .assertTiming();
  }
  public void testFindRootPerformance() throws IOException {
    File tempJar = IoTestUtil.createTestJar();
    final VirtualFile jar = refreshAndFindFile(tempJar);
    assertNotNull(jar);

    final JarFileSystem fs = JarFileSystem.getInstance();
    final NewVirtualFile root = ManagingFS.getInstance().findRoot(jar.getPath() + "!/", fs);
    PlatformTestUtil.startPerformanceTest(
            "find root is slow",
            500,
            new ThrowableRunnable() {
              @Override
              public void run() throws Throwable {
                final String path = jar.getPath() + "!/";
                JobLauncher.getInstance()
                    .invokeConcurrentlyUnderProgress(
                        Collections.nCopies(500, null),
                        null,
                        false,
                        new Processor<Object>() {
                          @Override
                          public boolean process(Object o) {
                            for (int i = 0; i < 1000; i++) {
                              NewVirtualFile rootJar = ManagingFS.getInstance().findRoot(path, fs);
                              assertNotNull(rootJar);
                              assertSame(root, rootJar);
                            }
                            return true;
                          }
                        });
              }
            })
        .assertTiming();
  }
예제 #5
0
  public void testFindChildByNamePerformance() throws IOException {
    File tempDir =
        new WriteAction<File>() {
          @Override
          protected void run(Result<File> result) throws Throwable {
            File res = createTempDirectory();
            result.setResult(res);
          }
        }.execute().getResultObject();
    final VirtualFile vDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempDir);
    assertNotNull(vDir);
    assertTrue(vDir.isDirectory());

    new WriteCommandAction.Simple(getProject()) {
      @Override
      protected void run() throws Throwable {
        for (int i = 0; i < 10000; i++) {
          final String name = i + ".txt";
          vDir.createChildData(vDir, name);
        }
      }
    }.execute();
    final VirtualFile theChild = vDir.findChild("5111.txt");
    System.out.println("Start searching...");
    PlatformTestUtil.startPerformanceTest(
            "find child is slow",
            450,
            new ThrowableRunnable() {
              @Override
              public void run() throws Throwable {
                for (int i = 0; i < 1000000; i++) {
                  VirtualFile child = vDir.findChild("5111.txt");
                  assertSame(theChild, child);
                }
              }
            })
        .assertTiming();

    new WriteCommandAction.Simple(getProject()) {
      @Override
      protected void run() throws Throwable {
        for (VirtualFile file : vDir.getChildren()) {
          file.delete(this);
        }
      }
    }.execute().throwException();
  }
  public void testPerformance() throws Exception {
    final String path = PathManagerEx.getTestDataPath() + "/psi/stub/StubPerformanceTest.java";
    String text = FileUtil.loadFile(new File(path));
    final PsiJavaFile file = (PsiJavaFile) createLightFile("test.java", text);

    PlatformTestUtil.startPerformanceTest(
            "Source file size: " + text.length(),
            2000,
            new ThrowableRunnable() {
              @Override
              public void run() throws Exception {
                NEW_BUILDER.buildStubTree(file);
              }
            })
        .cpuBound()
        .assertTiming();
  }
예제 #7
0
  public void testFindRootPerformance() {
    File tempDir =
        new WriteAction<File>() {
          @Override
          protected void run(Result<File> result) throws Throwable {
            File res = createTempDirectory();
            new File(res, "x.jar").createNewFile();
            result.setResult(res);
          }
        }.execute().getResultObject();
    final VirtualFile vDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempDir);
    final VirtualFile jar = vDir.findChild("x.jar");
    assertNotNull(jar);

    final NewVirtualFile root =
        ManagingFS.getInstance().findRoot(jar.getPath() + "!/", JarFileSystem.getInstance());
    PlatformTestUtil.startPerformanceTest(
            "find root is slow",
            500,
            new ThrowableRunnable() {
              @Override
              public void run() throws Throwable {
                final String path = jar.getPath() + "!/";
                final JarFileSystem fileSystem = JarFileSystem.getInstance();
                JobLauncher.getInstance()
                    .invokeConcurrentlyUnderProgress(
                        Collections.nCopies(500, null),
                        null,
                        false,
                        new Processor<Object>() {
                          @Override
                          public boolean process(Object o) {
                            for (int i = 0; i < 1000; i++) {
                              NewVirtualFile rootJar =
                                  ManagingFS.getInstance().findRoot(path, fileSystem);
                              assertNotNull(rootJar);
                              assertSame(root, rootJar);
                            }
                            return true;
                          }
                        });
              }
            })
        .assertTiming();
  }
  public void testCustomAttrsPerformance() throws Throwable {
    myFixture.copyFileToProject("dom/resources/bigfile.xml", "res/values/bigfile.xml");
    myFixture.copyFileToProject("dom/resources/bigattrs.xml", "res/values/bigattrs.xml");
    myFixture.copyFileToProject("dom/resources/bigattrs.xml", "res/values/bigattrs1.xml");
    myFixture.copyFileToProject("dom/resources/bigattrs.xml", "res/values/bigattrs2.xml");
    myFixture.copyFileToProject("dom/resources/bigattrs.xml", "res/values/bigattrs3.xml");
    VirtualFile f = copyFileToProject("bigfile.xml");
    myFixture.configureFromExistingVirtualFile(f);

    PlatformTestUtil.startPerformanceTest(
            "android custom attrs highlighting is slow",
            800,
            new ThrowableRunnable() {
              @Override
              public void run() throws Throwable {
                myFixture.doHighlighting();
              }
            })
        .attempts(2)
        .cpuBound()
        .usesAllCPUCores()
        .assertTiming();
  }
예제 #9
0
  public void testPerformance() {
    @NonNls
    final String longName =
        "ThisIsAQuiteLongNameWithParentheses().Dots.-Minuses-_UNDERSCORES_digits239:colons:/slashes\\AndOfCourseManyLetters";
    final List<MinusculeMatcher> matching = new ArrayList<MinusculeMatcher>();
    final List<MinusculeMatcher> nonMatching = new ArrayList<MinusculeMatcher>();

    for (String s :
        ContainerUtil.ar("*", "*i", "*a", "*u", "T", "ti", longName, longName.substring(0, 20))) {
      matching.add(new MinusculeMatcher(s, NameUtil.MatchingCaseSensitivity.NONE));
    }
    for (String s : ContainerUtil.ar("A", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "tag")) {
      nonMatching.add(new MinusculeMatcher(s, NameUtil.MatchingCaseSensitivity.NONE));
    }

    PlatformTestUtil.startPerformanceTest(
            "Matcher is slow",
            3000,
            new ThrowableRunnable() {
              @Override
              public void run() {
                for (int i = 0; i < 100000; i++) {
                  for (MinusculeMatcher matcher : matching) {
                    assertTrue(matcher.toString(), matcher.matches(longName));
                    matcher.matchingDegree(longName);
                  }
                  for (MinusculeMatcher matcher : nonMatching) {
                    assertFalse(matcher.toString(), matcher.matches(longName));
                  }
                }
              }
            })
        .cpuBound()
        .attempts(20)
        .assertTiming();
  }