|
19 | 19 | import java.util.ArrayList;
|
20 | 20 | import java.util.Collection;
|
21 | 21 | import java.util.List;
|
| 22 | +import java.util.Map; |
22 | 23 | import org.openjdk.jmh.results.RunResult;
|
23 | 24 | import org.openjdk.jmh.runner.Runner;
|
24 | 25 | import org.openjdk.jmh.runner.RunnerException;
|
@@ -208,5 +209,56 @@ private static void printBenchmarkSummary(List<BenchmarkResult> results) {
|
208 | 209 | System.out.println("=".repeat(140));
|
209 | 210 | System.out.printf("Total benchmark results: %d%n", sortedResults.size());
|
210 | 211 | System.out.println("=".repeat(140));
|
| 212 | + // Print performance comparison in between Apache clients |
| 213 | + printApachePerformanceComparison(results); |
| 214 | + |
211 | 215 | }
|
| 216 | + |
| 217 | + private static void printApachePerformanceComparison(List<BenchmarkResult> results) { |
| 218 | + if (results == null || results.isEmpty()) { |
| 219 | + return; |
| 220 | + } |
| 221 | + |
| 222 | + System.out.println("\nPERFORMANCE COMPARISON (Apache5 vs Apache4):"); |
| 223 | + System.out.println("=".repeat(80)); |
| 224 | + |
| 225 | + Map<String, List<BenchmarkResult>> groupedResults = results.stream() |
| 226 | + .filter(r -> r != null && r.getBenchmarkName() != null) |
| 227 | + .collect(Collectors.groupingBy(BenchmarkResult::getBenchmarkName)); |
| 228 | + |
| 229 | + for (Map.Entry<String, List<BenchmarkResult>> entry : groupedResults.entrySet()) { |
| 230 | + String benchmarkName = entry.getKey(); |
| 231 | + List<BenchmarkResult> benchmarkResults = entry.getValue(); |
| 232 | + |
| 233 | + // Find Apache4 baseline |
| 234 | + BenchmarkResult apache4 = benchmarkResults.stream() |
| 235 | + .filter(r -> r.getClientType() != null && r.getClientType().equals("Apache4")) |
| 236 | + .findFirst() |
| 237 | + .orElse(null); |
| 238 | + |
| 239 | + if (apache4 == null) { |
| 240 | + continue; |
| 241 | + } |
| 242 | + |
| 243 | + System.out.printf("\n%s:%n", benchmarkName); |
| 244 | + System.out.println("-".repeat(80)); |
| 245 | + |
| 246 | + for (BenchmarkResult result : benchmarkResults) { |
| 247 | + if (result.getClientType() != null && !result.getClientType().equals("Apache4")) { |
| 248 | + double throughputImprovement = ((result.getThroughput() - apache4.getThroughput()) |
| 249 | + / apache4.getThroughput()) * 100; |
| 250 | + double latencyImprovement = ((apache4.getAvgLatency() - result.getAvgLatency()) |
| 251 | + / apache4.getAvgLatency()) * 100; |
| 252 | + |
| 253 | + System.out.printf(" %-20s: %+.1f%% throughput, %+.1f%% latency improvement%n", |
| 254 | + result.getClientType(), |
| 255 | + throughputImprovement, |
| 256 | + latencyImprovement); |
| 257 | + } |
| 258 | + } |
| 259 | + } |
| 260 | + |
| 261 | + System.out.println("\n" + "=".repeat(80)); |
| 262 | + } |
| 263 | + |
212 | 264 | }
|
0 commit comments