Skip to content

Commit b3c015e

Browse files
[benchmark test] use average when asserting against performance threshold
The recently added assertion in the benchmark test, that confirm that the new async handler is much more performant vs the old sync handler, was failing the test once in a while. Originally the assertion was against each test run - those runs with fewer iterations were very sensitive to interference by e.g. GC. e.g. imagine that a 10-20 ms GC occurs while doing one of the runs below, while performing logging using "AsyncNew" - it could easily make "AsyncNew" look much less performant vs "SyncOld", once in a while making the AsyncNewVsSyncOld ratio look too low and failing the test : Runs(#) SyncOld(ms) AsyncNew(ms) AsyncNewVsSyncOld(rel perf) 2000 75.48 8.56 8.81x 4600 243.99 4.24 57.59x 10580 239.99 9.82 24.43x 24333 404.66 46.39 8.72x After this commit, the performance is asserted against the average performance of AsyncNew vs SyncOld, over the totals of all runs (separately for the Regular vs Lean benchmarks). The totals are also printed-out on stdout in human-readable form. Signed-off-by: Marc Dumais <marc.dumais@ericsson.com>
1 parent 85839ff commit b3c015e

File tree

1 file changed

+32
-12
lines changed

1 file changed

+32
-12
lines changed

src/test/java/org/eclipse/tracecompass/traceeventlogger/TestLoggerBenchmark.java

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ public String format(LogRecord record) {
9494
List<Long> syncNew = new ArrayList<>();
9595
List<Long> syncOld = new ArrayList<>();
9696
List<Long> run = new ArrayList<>();
97+
long totalRuns = 0;
98+
long totalAsyncNew = 0;
99+
long totalSyncOld = 0;
100+
97101
for (long runs = warmUp; runs < maxRuns; runs *= growth) {
98102
for (long i = 0; i < warmUp; i++) {
99103
try (LogUtils.ScopeLog log = new LogUtils.ScopeLog(logger, Level.FINE, "foo")) { //$NON-NLS-1$
@@ -220,6 +224,10 @@ public String format(LogRecord record) {
220224
for (int i = 0; i < run.size(); i++) {
221225
float factor = (float)syncOld.get(i) / (float)asyncNew.get(i);
222226
asyncNewVsSyncOld.add(factor);
227+
totalRuns += run.get(i);
228+
totalAsyncNew += asyncNew.get(i);
229+
totalSyncOld += syncOld.get(i);
230+
223231
System.out.println(String.format("%d,%d,%d,%d,%d,%.2f", run.get(i), syncOld.get(i), syncNew.get(i), //$NON-NLS-1$
224232
asyncOld.get(i), asyncNew.get(i), factor));
225233
}
@@ -230,13 +238,14 @@ public String format(LogRecord record) {
230238
System.out.println(String.format("%7d %13.2f %13.2f %13.2f %13.2f %27.2fx", run.get(i), syncOld.get(i)*0.000001, syncNew.get(i)*0.000001, //$NON-NLS-1$
231239
asyncOld.get(i)*0.000001, asyncNew.get(i)*0.000001, factor));
232240
}
241+
float avgFactor = (float)totalSyncOld / (float)totalAsyncNew;
242+
System.out.println("\n\"Regular\" - Total/Average"); //$NON-NLS-1$
243+
System.out.println("Runs(#) SyncOld(ms) AsyncNew(ms) AsyncNewVsSyncOld(rel perf)"); //$NON-NLS-1$
244+
System.out.println(String.format("%7d %13.2f %13.2f %27.2fx", totalRuns, totalSyncOld*0.000001, totalAsyncNew*0.000001, avgFactor));//$NON-NLS-1$
233245

234-
for (int i = 0; i < run.size(); i++) {
235-
float factor = asyncNewVsSyncOld.get(i);
236-
assertTrue("Runs: " + run.get(i) + " - AsyncNew expected to be much faster vs SyncOld! " + //$NON-NLS-1$//$NON-NLS-2$
237-
"Expected factor: > " + newAsyncPerformenceThreshold + "x, Actual: " + factor, //$NON-NLS-1$ //$NON-NLS-2$
238-
(factor > newAsyncPerformenceThreshold));
239-
}
246+
assertTrue("(Regular) On average AsyncNew is expected to be much faster vs SyncOld! " + //$NON-NLS-1$
247+
"Expected factor: > " + newAsyncPerformenceThreshold + "x, Actual: " + avgFactor, //$NON-NLS-1$ //$NON-NLS-2$
248+
(avgFactor > newAsyncPerformenceThreshold));
240249
}
241250

242251
private static long linecount(Path path) throws IOException {
@@ -305,6 +314,9 @@ public void testLeanBench() throws SecurityException, IOException {
305314
List<Long> syncNew = new ArrayList<>();
306315
List<Long> syncOld = new ArrayList<>();
307316
List<Long> run = new ArrayList<>();
317+
long totalRuns = 0;
318+
long totalAsyncNew = 0;
319+
long totalSyncOld = 0;
308320
for (long runs = warmUp; runs < maxRuns; runs *= growth) {
309321
for (long i = 0; i < warmUp; i++) {
310322
try (LogUtils.ScopeLog log = new LogUtils.ScopeLog(logger, Level.FINE, "foo")) { //$NON-NLS-1$
@@ -416,6 +428,9 @@ public void testLeanBench() throws SecurityException, IOException {
416428
for (int i = 0; i < run.size(); i++) {
417429
float factor = (float)syncOld.get(i) / (float)asyncNew.get(i);
418430
asyncNewVsSyncOld.add(factor);
431+
totalRuns += run.get(i);
432+
totalAsyncNew += asyncNew.get(i);
433+
totalSyncOld += syncOld.get(i);
419434
System.out.println(String.format("%d,%d,%d,%d,%d,%.2f", run.get(i), syncOld.get(i), syncNew.get(i), //$NON-NLS-1$
420435
asyncOld.get(i), asyncNew.get(i), factor));
421436
}
@@ -427,13 +442,18 @@ public void testLeanBench() throws SecurityException, IOException {
427442
System.out.println(String.format("%7d %13.2f %13.2f %13.2f %13.2f %27.2fx", run.get(i), syncOld.get(i)*0.000001, syncNew.get(i)*0.000001, //$NON-NLS-1$
428443
asyncOld.get(i)*0.000001, asyncNew.get(i)*0.000001, factor));
429444
}
445+
446+
float avgFactor = (float)totalSyncOld / (float)totalAsyncNew;
447+
System.out.println("\n\"Lean\" - Total/Average"); //$NON-NLS-1$
448+
System.out.println("Runs(#) SyncOld(ms) AsyncNew(ms) AsyncNewVsSyncOld(rel perf)"); //$NON-NLS-1$
449+
System.out.println(String.format("%7d %13.2f %13.2f %27.2fx", totalRuns, totalSyncOld*0.000001, totalAsyncNew*0.000001, avgFactor));//$NON-NLS-1$
450+
451+
assertTrue("(Lean) On average AsyncNew is expected to be much faster vs SyncOld! " + //$NON-NLS-1$
452+
"Expected factor: > " + newAsyncPerformenceThreshold + "x, Actual: " + avgFactor, //$NON-NLS-1$ //$NON-NLS-2$
453+
(avgFactor > newAsyncPerformenceThreshold));
454+
455+
430456
System.out.println("-----\n"); //$NON-NLS-1$
431-
for (int i = 0; i < run.size(); i++) {
432-
float factor = asyncNewVsSyncOld.get(i);
433-
assertTrue("Runs: " + run.get(i) + " - AsyncNewLean expected to be much faster vs SyncOldLean! " + //$NON-NLS-1$ //$NON-NLS-2$
434-
"Expected factor: > " + newAsyncPerformenceThreshold + "x, Actual: " + factor, //$NON-NLS-1$ //$NON-NLS-2$
435-
(factor > newAsyncPerformenceThreshold));
436-
}
437457
}
438458

439459
private static Handler makeAsyncFileHandler(String path) throws IOException {

0 commit comments

Comments
 (0)