summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/org/javacs/Profiler.java3
-rw-r--r--src/test/java/org/javacs/BenchmarkPruner.java63
2 files changed, 44 insertions, 22 deletions
diff --git a/src/main/java/org/javacs/Profiler.java b/src/main/java/org/javacs/Profiler.java
index c7b6911..e9c3635 100644
--- a/src/main/java/org/javacs/Profiler.java
+++ b/src/main/java/org/javacs/Profiler.java
@@ -8,6 +8,8 @@ import java.util.*;
import java.util.logging.Logger;
class Profiler implements TaskListener {
+ static boolean quiet = false;
+
Set<URI> files = new HashSet<>();
Map<URI, Map<TaskEvent.Kind, Instant>> started = new HashMap<>();
Map<TaskEvent.Kind, Duration> profile = new EnumMap<>(TaskEvent.Kind.class);
@@ -35,6 +37,7 @@ class Profiler implements TaskListener {
}
void print() {
+ if (quiet) return;
var lines = new StringJoiner("; ");
for (var kind : TaskEvent.Kind.values()) {
if (!profile.containsKey(kind)) continue;
diff --git a/src/test/java/org/javacs/BenchmarkPruner.java b/src/test/java/org/javacs/BenchmarkPruner.java
index 9ada490..a44d687 100644
--- a/src/test/java/org/javacs/BenchmarkPruner.java
+++ b/src/test/java/org/javacs/BenchmarkPruner.java
@@ -5,40 +5,59 @@ import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
+import java.util.logging.Logger;
import org.openjdk.jmh.annotations.*;
-@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
+@Warmup(iterations = 20, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@Fork(1)
public class BenchmarkPruner {
- private static SourceFileObject file = file(false);
- private static SourceFileObject pruned = file(true);
- private static JavaCompilerService compiler = createCompiler();
-
- private static SourceFileObject file(boolean prune) {
- var file = Paths.get("src/main/java/org/javacs/JavaCompilerService.java").normalize();
- if (prune) {
- var contents = Pruner.prune(file.toUri(), "isWord");
- return new SourceFileObject(file, contents);
- } else {
- return new SourceFileObject(file);
+
+ @State(Scope.Benchmark)
+ public static class CompilerState {
+ public SourceFileObject file = file(false);
+ public SourceFileObject pruned = file(true);
+ public JavaCompilerService compiler = createCompiler();
+
+ private static SourceFileObject file(boolean prune) {
+ var file = Paths.get("src/main/java/org/javacs/JavaCompilerService.java").normalize();
+ if (prune) {
+ var contents = Pruner.prune(file.toUri(), "isWord");
+ return new SourceFileObject(file, contents);
+ } else {
+ return new SourceFileObject(file);
+ }
+ }
+
+ private static JavaCompilerService createCompiler() {
+ LOG.info("Create new compiler...");
+
+ var workspaceRoot = Paths.get(".").normalize().toAbsolutePath();
+ FileStore.setWorkspaceRoots(Set.of(workspaceRoot));
+ var classPath = new InferConfig(workspaceRoot).classPath();
+ return new JavaCompilerService(classPath, Collections.emptySet());
+ }
+
+ @Setup
+ public void setup() {
+ Profiler.quiet = true;
}
- }
- private static JavaCompilerService createCompiler() {
- var workspaceRoot = Paths.get(".").normalize().toAbsolutePath();
- FileStore.setWorkspaceRoots(Set.of(workspaceRoot));
- var classPath = new InferConfig(workspaceRoot).classPath();
- return new JavaCompilerService(classPath, Collections.emptySet());
+ @TearDown
+ public void teardown() {
+ Profiler.quiet = false;
+ }
}
@Benchmark
- public void pruned() {
- compiler.compileBatch(List.of(pruned));
+ public void pruned(CompilerState state) {
+ state.compiler.compileBatch(List.of(state.pruned));
}
@Benchmark
- public void plain() {
- compiler.compileBatch(List.of(file));
+ public void plain(CompilerState state) {
+ state.compiler.compileBatch(List.of(state.file));
}
+
+ private static final Logger LOG = Logger.getLogger("main");
}