E5E7 fixed async benchmark - it was nonsensical before by bbakerman · Pull Request #3469 · graphql-java/graphql-java · GitHub
[go: up one dir, main page]

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 4 additions & 17 deletions src/test/java/benchmark/AsyncBenchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,37 +29,24 @@
@Fork(2)
public class AsyncBenchmark {

@Param({"0", "1", "10"})
public int num;
@Param({"1", "5", "20"})
public int numberOfFieldCFs;

List<CompletableFuture<Object>> futures;

@Setup(Level.Trial)
public void setUp() throws ExecutionException, InterruptedException {
futures = new ArrayList<>();
for (int i = 0; i < num; i++) {
for (int i = 0; i < numberOfFieldCFs; i++) {
futures.add(mkFuture(i));
}

}

private CompletableFuture<Object> mkFuture(int i) {
// half will take some time
if (i % 2 == 0) {
return CompletableFuture.supplyAsync(() -> sleep(i));
} else {
return CompletableFuture.completedFuture(i);
}
return CompletableFuture.completedFuture(i);
}

private Object sleep(int i) {
try {
Thread.sleep(i * 1000L);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return i;
}

@Benchmark
public List<Object> benchmarkAsync() {
Expand Down
0