diff --git a/JetStreamDriver.js b/JetStreamDriver.js index c88015d9..4045787b 100644 --- a/JetStreamDriver.js +++ b/JetStreamDriver.js @@ -1495,7 +1495,7 @@ class DefaultBenchmark extends Benchmark { this.firstIterationScore = toScore(results[0]); results = results.slice(1); - results.sort((a, b) => a < b ? 1 : -1); + results.sort((a, b) => b - a); for (let i = 0; i + 1 < results.length; ++i) console.assert(results[i] >= results[i + 1]); diff --git a/tests/unit-tests.js b/tests/unit-tests.js index 665c7fa8..d4b1ee86 100644 --- a/tests/unit-tests.js +++ b/tests/unit-tests.js @@ -158,6 +158,27 @@ function assertThrows(message, func) { } })(); +(function testDefaultBenchmarkResultsWithTies() { + // Many iterations hit the 1 ms timing floor. Ties must not hide the slowest samples. + const results = Array(64).fill(1); + for (const index of [49, 53, 59, 63]) + results[index] = 4; + results[40] = results[62] = 2; + + const benchmark = new DefaultBenchmark({ + name: "results-with-ties", + files: [], + tags: ["js"], + iterations: results.length + 1, + worstCaseCount: 4, + }); + benchmark.processResults([1000, ...results]); + + assertEquals(benchmark.firstIterationTime, 1000); + assertEquals(benchmark.worstTime, 4); + assertEquals(benchmark.averageTime, (64 + 4 * (4 - 1) + 2 * (2 - 1)) / results.length); +})(); + (function checkUtf16Sources() { // Test that only explicitly UTF16-enabled benchmarks can have sources // with non-8-byte characters.