From 78f6243b631aa6047a35524d3a5908f3683171e4 Mon Sep 17 00:00:00 2001 From: Brad Baker Date: Sat, 24 Feb 2024 14:01:16 +1100 Subject: [PATCH] fixed async benchmark - it was non sensical before --- src/test/java/benchmark/AsyncBenchmark.java | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/src/test/java/benchmark/AsyncBenchmark.java b/src/test/java/benchmark/AsyncBenchmark.java index 4a3482b855..cc52db226e 100644 --- a/src/test/java/benchmark/AsyncBenchmark.java +++ b/src/test/java/benchmark/AsyncBenchmark.java @@ -29,37 +29,24 @@ @Fork(2) public class AsyncBenchmark { - @Param({"0", "1", "10"}) - public int num; + @Param({"1", "5", "20"}) + public int numberOfFieldCFs; List> 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 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 benchmarkAsync() {