diff options
author | George Fraser <george@fivetran.com> | 2019-01-03 23:01:53 -0800 |
---|---|---|
committer | George Fraser <george@fivetran.com> | 2019-01-03 23:01:53 -0800 |
commit | 6eba663e82a9903a79e329d9f75b77a7cd75255b (patch) | |
tree | eae515cfbe670529d96debc0a06606f9eced0833 /src/test/java | |
parent | 1a4d6fb2051fd02f95bf52dcfbe997ef71ef7095 (diff) | |
download | java-language-server-6eba663e82a9903a79e329d9f75b77a7cd75255b.zip |
Prune reference and definition searches
Diffstat (limited to 'src/test/java')
-rw-r--r-- | src/test/java/org/javacs/BenchmarkErrorProne.java (renamed from src/test/java/org/javacs/ErrorProneBenchmark.java) | 2 | ||||
-rw-r--r-- | src/test/java/org/javacs/BenchmarkPruner.java | 63 | ||||
-rw-r--r-- | src/test/java/org/javacs/BenchmarkStringSearch.java (renamed from src/test/java/org/javacs/StringSearchBenchmark.java) | 2 | ||||
-rw-r--r-- | src/test/java/org/javacs/PrunerTest.java | 7 |
4 files changed, 72 insertions, 2 deletions
diff --git a/src/test/java/org/javacs/ErrorProneBenchmark.java b/src/test/java/org/javacs/BenchmarkErrorProne.java index 6e0b7ba..ff3f64e 100644 --- a/src/test/java/org/javacs/ErrorProneBenchmark.java +++ b/src/test/java/org/javacs/BenchmarkErrorProne.java @@ -20,7 +20,7 @@ import org.openjdk.jmh.annotations.*; @Warmup(iterations = 3, time = 1, timeUnit = TimeUnit.SECONDS) @Measurement(iterations = 3, time = 1, timeUnit = TimeUnit.SECONDS) @Fork(1) -public class ErrorProneBenchmark { +public class BenchmarkErrorProne { private static Path file = Paths.get(FindResource.uri("/org/javacs/example/BenchmarkStringSearch.java")); @State(Scope.Thread) diff --git a/src/test/java/org/javacs/BenchmarkPruner.java b/src/test/java/org/javacs/BenchmarkPruner.java new file mode 100644 index 0000000..c212cd8 --- /dev/null +++ b/src/test/java/org/javacs/BenchmarkPruner.java @@ -0,0 +1,63 @@ +package org.javacs; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.TimeUnit; +import org.openjdk.jmh.annotations.*; + +@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS) +@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS) +@Fork(1) +public class BenchmarkPruner { + private static Path sourceRoot = Paths.get("src/main/java").normalize(); + private static List<StringFileObject> files = files(false); + private static List<StringFileObject> pruned = files(true); + + private static List<StringFileObject> files(boolean prune) { + try { + var files = new ArrayList<StringFileObject>(); + var dir = Paths.get("src/main/java/org/javacs").normalize(); + var it = Files.list(dir).iterator(); + while (it.hasNext()) { + var file = it.next(); + if (!Files.isRegularFile(file)) continue; + var contents = String.join("\n", Files.readAllLines(file)); + ; + if (prune) { + contents = Pruner.prune(file.toUri(), contents, "isWord"); + } + files.add(new StringFileObject(contents, file.toUri())); + } + return files; + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + private static JavaCompilerService createCompiler() { + return new JavaCompilerService( + Collections.singleton(sourceRoot), + () -> { + throw new RuntimeException("Unimplemented"); + }, + Collections.emptySet(), + Collections.emptySet()); + } + + @Benchmark + public void pruned() { + var compiler = createCompiler(); + compiler.compileBatch(pruned); + } + + @Benchmark + public void plain() { + var compiler = createCompiler(); + compiler.compileBatch(files); + } +} diff --git a/src/test/java/org/javacs/StringSearchBenchmark.java b/src/test/java/org/javacs/BenchmarkStringSearch.java index e044812..1c453d2 100644 --- a/src/test/java/org/javacs/StringSearchBenchmark.java +++ b/src/test/java/org/javacs/BenchmarkStringSearch.java @@ -9,7 +9,7 @@ import org.openjdk.jmh.annotations.*; @Warmup(iterations = 3, time = 1, timeUnit = TimeUnit.SECONDS) @Measurement(iterations = 3, time = 1, timeUnit = TimeUnit.SECONDS) @Fork(1) -public class StringSearchBenchmark { +public class BenchmarkStringSearch { private static final Path largeFile = Paths.get(FindResource.uri("/org/javacs/example/LargeFile.java")), smallFile = Paths.get(FindResource.uri("/org/javacs/example/Goto.java")); // "removeMethodBodies" appears late in the file, so stopping early will not be very effective diff --git a/src/test/java/org/javacs/PrunerTest.java b/src/test/java/org/javacs/PrunerTest.java index 24098be..50e511f 100644 --- a/src/test/java/org/javacs/PrunerTest.java +++ b/src/test/java/org/javacs/PrunerTest.java @@ -36,4 +36,11 @@ public class PrunerTest { var expected = contents("PruneDot_erased.java"); assertThat(actual, equalToIgnoringWhiteSpace(expected)); } + + @Test + public void pruneWords() { + var actual = Pruner.prune(URI.create("/PruneWords.java"), contents("PruneWords.java"), "word"); + var expected = contents("PruneWords_erased.java"); + assertThat(actual, equalToIgnoringWhiteSpace(expected)); + } } |