diff options
Diffstat (limited to 'src/test')
-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 | ||||
-rw-r--r-- | src/test/test-project/simple/PruneWords.java | 13 | ||||
-rw-r--r-- | src/test/test-project/simple/PruneWords_erased.java | 13 |
6 files changed, 98 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)); + } } diff --git a/src/test/test-project/simple/PruneWords.java b/src/test/test-project/simple/PruneWords.java new file mode 100644 index 0000000..3d0e2bd --- /dev/null +++ b/src/test/test-project/simple/PruneWords.java @@ -0,0 +1,13 @@ +class PruneWords { + void keepThis() { + word(); + } + + void eraseThis() { + notword(); + } + + void keepThisToo() { + word(); + } +}
\ No newline at end of file diff --git a/src/test/test-project/simple/PruneWords_erased.java b/src/test/test-project/simple/PruneWords_erased.java new file mode 100644 index 0000000..873f9cf --- /dev/null +++ b/src/test/test-project/simple/PruneWords_erased.java @@ -0,0 +1,13 @@ +class PruneWords { + void keepThis() { + word(); + } + + void eraseThis() { + + } + + void keepThisToo() { + word(); + } +}
\ No newline at end of file |