-
Notifications
You must be signed in to change notification settings - Fork 154
Expand file tree
/
Copy pathBenchmarkPruner.java
More file actions
63 lines (52 loc) · 2.1 KB
/
BenchmarkPruner.java
File metadata and controls
63 lines (52 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package org.javacs;
import org.javacs.completion.PruneMethodBodies;
import org.openjdk.jmh.annotations.*;
import java.nio.file.Paths;
import java.time.Instant;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;
@Warmup(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 5, time = 1, timeUnit = TimeUnit.SECONDS)
@Fork(1)
public class BenchmarkPruner {
@State(Scope.Benchmark)
public static class CompilerState {
public SourceFileObject file = file(false);
public SourceFileObject pruned = file(true);
public JavaCompilerService compiler = createCompiler();
private SourceFileObject file(boolean prune) {
var file = Paths.get("src/main/java/org/javacs/InferConfig.java").normalize();
if (prune) {
var task = compiler.parse(file);
var contents = new PruneMethodBodies(task.task).scan(task.root, 11222L).toString();
return new SourceFileObject(file, contents, Instant.now());
} 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(), Collections.emptySet(), Docs.NOT_FOUND);
}
}
@Benchmark
public void parsePlain(CompilerState state) {
Parser.parseJavaFileObject(state.file);
}
@Benchmark
public void compilePruned(CompilerState state) {
state.compiler.compile(List.of(state.pruned)).close();
}
@Benchmark
public void compilePlain(CompilerState state) {
state.compiler.compile(List.of(state.file)).close();
}
private static final Logger LOG = Logger.getLogger("main");
}