Skip to content

Commit

Permalink
refactor: cleanup speed ratio computation
Browse files Browse the repository at this point in the history
Signed-off-by: Jérôme Benoit <[email protected]>
  • Loading branch information
jerome-benoit committed Apr 14, 2024
1 parent f8b1e13 commit db6dc8f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/reporter/fmt.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function errorMargin(rmoe) {
.replaceAll(',', "'")} %`;
}

export function speedRate(speed) {
export function speedRatio(speed) {
return `${Number(speed.toFixed(2))
.toLocaleString(locale)
.replaceAll(',', "'")}`;
Expand Down
10 changes: 5 additions & 5 deletions src/reporter/table.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { tatamiNgGroup } from '../constants.mjs';
import * as clr from './clr.mjs';
import { duration, errorMargin, iterPerSecond, speedRate } from './fmt.mjs';
import { duration, errorMargin, iterPerSecond, speedRatio } from './fmt.mjs';

export function size(names) {
let size = 9;
Expand Down Expand Up @@ -134,11 +134,11 @@ export function summary(benchmarks, { colors = true }) {
}`}\n ${clr.bold(colors, clr.cyan(colors, baseline.name))}${benchmarks
.filter(benchmark => benchmark !== baseline)
.map(benchmark => {
const rate = (1 / baseline.stats.avg) * benchmark.stats.avg;
return `\n ${clr[1 > rate ? 'red' : 'green'](
const ratio = benchmark.stats.avg / baseline.stats.avg;
return `\n ${clr[1 > ratio ? 'red' : 'green'](
colors,
1 > rate ? speedRate(1 / rate) : speedRate(rate),
)}x ${1 > rate ? 'slower' : 'faster'} than ${clr.bold(
1 > ratio ? speedRatio(1 / ratio) : speedRatio(ratio),
)}x ${1 > ratio ? 'slower' : 'faster'} than ${clr.bold(
colors,
clr.cyan(colors, benchmark.name),
)}`;
Expand Down

0 comments on commit db6dc8f

Please sign in to comment.